繁体   English   中英

AWS::AppSync::Resolver 在 CloudFormation.yml 中使用 javascript 无法构建

[英]AWS::AppSync::Resolver using javascript in CloudFormation .yml fails to build

我在创建 AWS::AppSync::Resolver 时遇到问题,它是一种 PIPELINE 类型,写在 JavaScript 中。我认为问题在于我为Code:因为在 AWS 文档中,它没有详细解释它只是说它是字符串类型。 所以我假设它和我使用 VTL 编写代码一样,所以我将 JS 代码直接放入Code:参数的 .yml 文件中。

UpsertMappingDataResolver:
  Type: AWS::AppSync::Resolver
  Properties:
    ApiId: !GetAtt GraphQLApi.ApiId
    TypeName: "Mutation"
    FieldName: "upsertDataWithMapping"
    Kind: PIPELINE
    Code: "export function request(ctx) {
        return {
            foo: 'bar'
        };
    }
    
    export function response(ctx) {
        if(ctx.prev.result) return 1;
        return 0;
    }"
    Runtime:
      Name: APPSYNC_JS
      RuntimeVersion: "1.0.0"
    PipelineConfig:
      Functions:
        - !GetAtt UpsertItem.FunctionId
        - !GetAtt UpsertIntegrationMappingItem.FunctionId
  DependsOn:
    - Schema

所以我尝试了这个,但是 CloudFormation 构建失败并出现以下错误:代码包含一个或多个错误。 (服务:AWSAppSync;状态代码:400;错误代码:BadRequestException;请求 ID:0245d64d-...;代理:空)

您的代码块缺少 YAML多行代码指示符(例如| ):

Code: |
    export function request(ctx) {
        return {
            foo: 'bar'
        };
    }

    export function response(ctx) {
        if(ctx.prev.result) return 1;
        return 0;
    }

与此同时,我设法解决了它,看起来 APPSYNC_JS 运行时不支持箭头函数,并且在我的原始代码中我有一个 forEach(()=>{}) 方法,这就是我的代码崩溃的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM