Score:0

AWS SAM - cannot create stack with api gateway using stage variable for invoked lambda version

mx flag

Ok, previous question about using different lambda versions on different stages here: AWS - lambda versions to different gateway stages?

Now I'm trying to put it all together using AWS SAM cli but still getting an error:

template.yaml

Relevant parts of my template


Resources:
  AppApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: HelloWorldApiGateway

  HelloWorldResource:
    Type: AWS::ApiGateway::Resource
    Properties:
      RestApiId: !Ref AppApi
      ParentId: !GetAtt AppApi.RootResourceId
      PathPart: hello-world

  ResourceMethodGet:
    Type: AWS::ApiGateway::Method
    Properties:
      AuthorizationType: NONE
      RestApiId: !Ref AppApi
      ResourceId: !Ref HelloWorldResource
      HttpMethod: GET
      Integration:
        Type: AWS
        IntegrationHttpMethod: GET
        Uri: !Join
          - ""
          - - "arn:aws:apigateway:"
            - ${AWS::Region}
            - "lambda:path/2015-03-31/functions/"
            - !GetAtt HelloWorldFunction.Arn
            - ":${lambda_alias}"
            - "/invocations"

  ProductionStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      RestApiId: !Ref AppApi
      StageName: production
      DeploymentId: !Ref ProductionDeployment
      Variables:
        function_alias: production

  StagingStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      RestApiId: !Ref AppApi
      StageName: staging
      DeploymentId: !Ref StagingDeployment
      Variables:
        function_alias: staging

  ProductionDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref AppApi

  StagingDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref AppApi

  HelloWorldFunction:
    Type: AWS::Serverless::Function
    # ...

  FunctionStagingAlias:
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName: !Ref HelloWorldFunction
      Name: "staging"
      FunctionVersion: $LATEST

  FunctionProductionAlias:
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName: !Ref HelloWorldFunction
      Name: "production"
      FunctionVersion: 2 # Just an example

The error

sam build && sam sync --stack-name hello-world-app

CloudFormation events from stack operations (refresh every 0.5 seconds)
---------------------------------------------
ResourceStatus                      ResourceType                        LogicalResourceId                   ResourceStatusReason              
---------------------------------------------

... non-error events ...

UPDATE_IN_PROGRESS                  AWS::ApiGateway::Method             ResourceMethodGet                   -                                 
UPDATE_FAILED                       AWS::ApiGateway::Method             ResourceMethodGet                   AWS ARN for integration must      
                                                                                                            contain path or action (Service:  
                                                                                                            AmazonApiGateway; Status Code:    
                                                                                                            400; Error Code:                  
                                                                                                            BadRequestException; Request ID:  
                                                                                                            7ea71b09-062b-41d3-89e1-e567c0cd3 
                                                                                                            85e; Proxy: null)                 
UPDATE_ROLLBACK_IN_PROGRESS         AWS::CloudFormation::Stack          hello-world-app                     The following resource(s) failed  
                                                                                                            to update: [ResourceMethodGet].  

... rollback ...
Tim avatar
gp flag
Tim
The error message says "AWS ARN for integration must contain path or action". Have you searched for that error message? I found this which may help https://stackoverflow.com/questions/50692416/getting-an-error-trying-to-create-an-aws-api-gateway-via-cloudformation
fudo avatar
mx flag
@Tim of course I looked for it, but according to the [Uri property documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration.html#cfn-apigateway-method-integration-uri) the string I'm building with `!Join` seems to be correct as it contains a valid `path` 'segment'
Tim avatar
gp flag
Tim
I would be trying to show exactly what that join expression evaluates to, perhaps by putting it as a tag on another object, and commenting out the part that's not working.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.