我在使用 Javascript 解析器在无服务器框架中创建 AWS::Appsync:Resolver Cloudformation 时遇到问题。
My Javascript Resolver
我附加到的根目录 /src/resolvers/jsResolver.js 中的代码AWS::AppSync::Resolver
代码块中的cloudformation。我还在我的 package.json 中安装了 appsync utils 的 npm 插件
import { util } from '@aws-appsync/utils';
export function request(ctx) {
const {source, args} = ctx
return {
operation: 'Invoke',
payload: { field: ctx, arguments: args, source },
};
}
export function response(ctx) {
util.error("Failed to fetch relatedPosts", "LambdaFailure", ctx.prev.result)
return ctx.result;
}
My AWS::AppSync::Resolver
Cloudformation 位于 YML 文件下方,如果我将其声明为,我也使用代码作为其强制项APPSYNC_JS 运行时
AppSyncJsResolver:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GettAtt Graphql.APiId
Kind: PIPELINE
Code: ./src/resolvers/jsResolver.js <—- Here my code is breaking up with error contains one or more error
TypeName: Query
FieldName: getInfo
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
PipelineConfig:
Functions:
- !GetAtt AppSyncFunction.FunctionId
我已经按照 AWS Cloudformation 文档尝试了上面的代码,他们在其中提到了 AppsyncAWS::AppSync::Resolver
用于使用 Cloudformation 创建 Javascript Resolver,如下属性之一。我已将其包含在我的AWS::AppSync::Resolver
Code
The resolver code that contains the request and response functions. When code is
used, the runtime is required. The runtime value must be APPSYNC_JS.
Required: No
Type: String
Required: No
Type: String
所以我尝试过这个,但找不到足够的关于 Javascript 解析器的解决方案,所有这些解决方案都适用于特定的 VTL 模板。
使用上面的代码,我的 CloudFormation 构建失败并出现以下错误:发生错误:AppSyncJSResolver - 代码包含一个或多个错误。(服务:AWSAppSync;状态代码:400;错误代码:BadRequestException;请求 ID:0245d64d-...;代理:null)
- AppSync JS Resolver - 这是我的
AWS::AppSync::Resolver
在上面的代码中。我有代码属性,这给了我一个错误。我已经通过多个来源进行了验证,并且我没有发现我的任何错误JavaScript 解析器我在其中声明的文件 /src/resolvers/jsResolver.jsAppSync JS 解析器 AWS::AppSync::Resolver
在代码属性中,我不确定为什么会收到此错误,任何帮助都会很棒。