Home > other >  AWS::AppSync::Resolver using javascript in CloudFormation .yml fails to build
AWS::AppSync::Resolver using javascript in CloudFormation .yml fails to build

Time:12-09

I'm having problems creating an AWS::AppSync::Resolver that is a PIPELINE kind, written in JavaScript. I think that the problem lies in what i write for Code: since in AWS docs it is not explained to details it only says that it is of type String. So i went with the assumption that it is the same as if i were to write code using VTL so i put the JS code directly into the .yml file for Code: parameter.

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

So i tried this, but the CloudFormation build failed with the following this error: The code contains one or more errors. (Service: AWSAppSync; Status Code: 400; Error Code: BadRequestException; Request ID: 0245d64d-...; Proxy: null)

CodePudding user response:

Your code block is missing a YAML multi-line code indicator (e.g. |):

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

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

CodePudding user response:

I managed to solve it in the meantime, it looks like the APPSYNC_JS runtime does not support arrow functions, and in my original code I had a forEach(()=>{}) method which was why my code was crashing.

  • Related