aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Pushing multiple custom resolver #1518

Closed antoine-doolaeghe closed 5 years ago

antoine-doolaeghe commented 5 years ago

Custom Resolver pointing to a lambda function

I have successfully added an initial custom resolver following the instruction from here https://aws-amplify.github.io/docs/cli/graphql#add-a-custom-resolver-that-targets-a-dynamodb-table-from-model.

However, when trying to add a secondary custom resolver pointing to another function, then pushing again using the cli command amplify push, it resolves in an Resource is not in the state stackUpdateComplete error.

The updated resource in CustomResources.json are the following :

"TerminateLambdaDataSource": {
      "Type": "AWS::AppSync::DataSource",
      "Properties": {
        "ApiId": {
          "Ref": "AppSyncApiId"
        },
        "Name": "TerminateFunction",
        "Type": "AWS_LAMBDA",
        "ServiceRoleArn": {
          "Fn::GetAtt": ["TerminateLambdaDataSourceRole", "Arn"]
        },
        "LambdaConfig": {
          "LambdaFunctionArn": {
            "Fn::Sub": [
              "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:ec2terminate-${env}",
              {
                "env": {
                  "Ref": "env"
                }
              }
            ]
          }
        }
      }
    },
    "TerminateLambdaDataSourceRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": {
          "Fn::Sub": [
            "TerminateLambdaDataSourceRole-${env}",
            {
              "env": {
                "Ref": "env"
              }
            }
          ]
        },
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": "appsync.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": "InvokeLambdaFunction",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": ["lambda:invokeFunction"],
                  "Resource": [
                    {
                      "Fn::Sub": [
                        "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:ec2terminate-${env}",
                        {
                          "env": {
                            "Ref": "env"
                          }
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
    },
    "QueryTerminateResolver": {
      "Type": "AWS::AppSync::Resolver",
      "Properties": {
        "ApiId": {
          "Ref": "AppSyncApiId"
        },
        "DataSourceName": {
          "Fn::GetAtt": ["TerminateLambdaDataSource", "Name"]
        },
        "TypeName": "Query",
        "FieldName": "terminate",
        "RequestMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.terminate.req.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        },
        "ResponseMappingTemplateS3Location": {
          "Fn::Sub": [
            "s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.terminate.req.vtl",
            {
              "S3DeploymentBucket": {
                "Ref": "S3DeploymentBucket"
              },
              "S3DeploymentRootKey": {
                "Ref": "S3DeploymentRootKey"
              }
            }
          ]
        }
      }
    }

The resolver with the following relative path amplify/backend/api/newbornapp/resolvers/Query.terminate.req.vtl

{
    "version": "2017-02-28",
    "operation": "Invoke",
    "payload": {
        "type": "Query",
        "field": "terminate",
        "arguments": $utils.toJson($context.arguments),
        "identity": $utils.toJson($context.identity),
        "source": $utils.toJson($context.source)
    }
}

Any help with this would be much appreciated.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.