AWS SAM-无法使用阶段变量为调用的 lambda 版本创建带有 api 网关的堆栈

AWS SAM-无法使用阶段变量为调用的 lambda 版本创建带有 api 网关的堆栈

好的,之前关于在不同阶段使用不同 lambda 版本的问题在这里:AWS-lambda 版本到不同的网关阶段?

现在我尝试使用 AWS SAM cli 将所有内容整合在一起但仍然收到错误:

模板.yaml

我的模板的相关部分


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

错误

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 ...

相关内容