0

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 ...
fudo
  • 141
  • 1
  • 6
  • 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 – Tim Jan 10 '23 at 17:47
  • @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' – fudo Jan 11 '23 at 08:09
  • 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. – Tim Jan 11 '23 at 18:08

0 Answers0