简体   繁体   English

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

[英]How to pass AWS AccountId in REST API's uri(Cloudformation)

Code:代码:

  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"

If use Pseudo Parameters like below i'm facing issue.如果使用如下伪参数,我将面临问题。

Updated Code:更新代码:

 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"

Error:错误:

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)

Thanks in advance.提前致谢。

Naresh纳雷什

First, you should remove your AWS Account ID from the question.首先,您应该从问题中删除您的 AWS 账户 ID。

If you're using a SAM Template YAML file and passing variables to your template during your pipeline stage via ParameterOverrides you should then have parameters declared at the top of the file in your SAM Template YAML file and your code should be as an example POST.如果您使用的是 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

This is assuming this piece of code is attached to:这是假设这段代码附加到:

Type: AWS::Serverless::Api

Without any other information I'm just assuming what you're trying to do.没有任何其他信息,我只是假设您要做什么。

As a side note, you can access your account id in CloudFormation like so:作为旁注,您可以在 CloudFormation 中访问您的帐户 ID,如下所示:

${AWS::AccountId}

Use of Pseudo Parameters in the SAM AWS::Serverless::Api resource has been documented in this realworld SAM example Github https://github.com/awslabs/realworld-serverless-application/wiki/Amazon-API-Gateway#use-awsserverlessapi-in-your-cloudformation-template在这个真实世界的 SAM 示例 Github https://github.com/awslabs/realworld-serverless-application/wiki/Amazon-API-Gateway#use- 中记录了在 SAM AWS::Serverless::Api 资源中使用伪参数awsserverlessapi-in-your-cloudformation-template

The example using AWS::Include allows the use of Pseudo Parameters in the swagger file.使用AWS::Include的示例允许在 swagger 文件中使用伪参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CloudFormation:如何在映射中使用AWS :: AccountId? - CloudFormation: How to use AWS::AccountId in Mappings? 如何使用 AWS CloudFormation 为我的其余 API 创建自定义 API 域名 - How to create a custom api domain name for my rest API using AWS CloudFormation 如何模拟 Moto 的 AccountId - How to mock Moto's AccountId 如何在 AWS CloudFormation 部署中将参数作为文件传递? - How to pass parameter as a file in AWS CloudFormation deploy? 如何使用aws中的cloudformation在api网关中请求参数并将其传递给lambda函数? - How can I request parameters in api gateway using cloudformation in aws and pass it down to lambda function? 如何在无服务器配置文件中设置AWS :: AccountId? - how to set AWS::AccountId in serverless config file? AWS Grafana/CloudWatch - 如何通过 accountId 显示账单 - AWS Grafana/CloudWatch - How to show Bill by accountId 如何将参数从CloudFormation传递到S3存储桶中存储的AWS Lambda函数 - How to pass a parameter from CloudFormation to an AWS Lambda function stored in an S3 bucket AWS CloudFormation:如何输出机器的PublicIP? - AWS CloudFormation: How to output a machine's PublicIP? 如何在 CloudFormation 模板中将 AWS::ApiGateway::Resource 添加到 AWS::Serverless::Api - How to add an AWS::ApiGateway::Resource to an AWS::Serverless::Api in CloudFormation template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM