如何在REST API的uri(Cloudformation)中传递AWS AccountId

时间:2018-10-23 22:32:56

标签: amazon-web-services aws-lambda amazon-cloudformation

代码:

  x-amazon-apigateway-integration:
    uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:428377611111:function:${stageVariables.target_lambdaName}/invocations"

如果使用如下所示的伪参数,则面临问题。

更新代码:

 x-amazon-apigateway-integration:
    uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:${AWS::AccountId}:function:${stageVariables.target_lambdaName}/invocations"

错误:

Errors found during import: Unable to put integration on 'GET' for resource at path '/getMessage': Invalid HTTP endpoint specified for URI (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 3da76bd8-d714-11e8-8ec4-4b324c6636a4)

谢谢。

Naresh

2 个答案:

答案 0 :(得分:0)

首先,您应该从问题中删除您的AWS账户ID。

如果您正在使用SAM模板YAML文件,并在管道阶段通过ParameterOverrides将变量传递到模板中,则应该在SAM模板YAML文件的文件顶部声明参数,并且代码应与示例POST。

paths:
        /PATH_NAME:
          get:
            responses: {}
            x-amazon-apigateway-integration:
              uri:
                Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FUNCTION_NAME_HERE.Arn}/invocations
              httpMethod: POST
              type: aws_proxy

这是假定这段代码已附加到:

Type: AWS::Serverless::Api

没有任何其他信息,我只是假设您要尝试做的事情。

请注意,您可以像这样在CloudFormation中访问您的帐户ID:

${AWS::AccountId}

答案 1 :(得分:0)

在此真实SAM示例Github https://github.com/awslabs/realworld-serverless-application/wiki/Amazon-API-Gateway#use-awsserverlessapi-in-your-cloudformation-template

中已记录了SAM AWS :: Serverless :: Api资源中伪参数的使用。

使用AWS::Include的示例允许在swagger文件中使用伪参数。