Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom DataSource as a dependency to an auto-generated resolver function. #942

Closed
LukeHalby opened this issue Nov 1, 2022 · 1 comment
Labels
api-graphql duplicate This issue or pull request already exists extensibility question Further information is requested

Comments

@LukeHalby
Copy link

Which Category is your question related to?
API

Amplify CLI Version
10.2.3

Details

I have extended an auto-generated pipeline resolver by added 2 postUpdate functions to it (as shown below).
image

The MutationcreateChatroompostUpdate1Function function makes a BatchPutItem request to a DynamoDB table. I had originally created that DataSource on the web console but now I need it to be defined locally and have it update upon amplify push.

I originally added the following code to my CustomResource.json file, but the auto-generated stack failed update because it needs this as a dependency.

    "BatchRequestDataSource": {
      "Type" : "AWS::AppSync::DataSource",
      "Properties" : {
          "ApiId" : { "Ref": "AppSyncApiId" },
          "Description" : "A non-existent table to be used as a DataSource for batch requests in resolvers",
          "DynamoDBConfig" : {
            "AwsRegion": "ap-southeast-2",
            "TableName": "empty"
          },
          "Name" : "BATCH_DS",
          "ServiceRoleArn" : "MyBatchReadWriteArn",
          "Type" : "AMAZON_DYNAMODB"
        }
    }

I then tried to create the resource in overrides.ts with aws-cdk and use it in the .addDependsOn() method, but that failed on push with Error: Skipping override due to VMError: Cannot find module 'fs'.

    const batch = new CfnDataSource(this, 'BatchRequestDataSource', {
        apiId: resources.api.GraphQLAPI.attrApiId,
        description: "A non-existent table to be used as a DataSource for batch requests in resolvers",
        dynamoDbConfig: {
            tableName: "empty",
            awsRegion: "ap-southeast-2"
        },
        name: BATCH_DS,
        serviceRoleArn: "MyBatchReadWriteArn",
        type: "AMAZON_DYNAMODB"
    })

Scoured this repo for related issues but found nothing, any help is welcome and much appreciated!

@LukeHalby LukeHalby added the question Further information is requested label Nov 1, 2022
@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Nov 1, 2022
@ykethan
Copy link

ykethan commented Nov 1, 2022

Hey @LukeHalby, thank you for reaching out. The issue is similar to #109. In a custom CDK resource using amplify add custom fs ops are permitted and we should be able to add a DataSource to a resolver: https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-appsync.Resolver.html#class-resolver-construct-span-classapi-icon-api-icon-experimental-titlethis-api-element-is-experimental-it-may-change-without-noticespan.
Additionally, please refer to the RFC: #430 (comment) to enable Datasource for pipeline resolvers

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
@ykethan ykethan added the duplicate This issue or pull request already exists label Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-graphql duplicate This issue or pull request already exists extensibility question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants