0

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)

2 Answers2

0

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;
    }
fedonev
  • 20,327
  • 2
  • 25
  • 34
  • can you please look into this question and suggest possible solution https://stackoverflow.com/questions/75422633/awsappsyncfunctionconfiguration-cloudformation-error-using-javascript-resolve – Cloudformation Feb 11 '23 at 21:56
0

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.

  • Hello @JovanKecojevic, can you share your aws::AppSync::functionconfiguration code as in my pipeline config I have define that function, so I have code block in that function, and it’s giving me an same error as yours the code contains one or more error – Cloudformation Feb 11 '23 at 16:42
  • I have created one JavaScript resolver js which contains resolver code, I have take reference for that code from aws docs, but it’s still having same as code contains one or more error. I have Checked everything that it’s not containing arrow or foreach like that. It’s driving me nuts. – Cloudformation Feb 11 '23 at 16:46
  • I have asked same question here if you can look into it https://stackoverflow.com/questions/75422633/awsappsyncfunctionconfiguration-cloudformation-error-using-javascript-resolve – Cloudformation Feb 11 '23 at 21:57