amazon-web-services - 无法在 Cloudformation 模板中为 AWS::ApiGateway::Resource 指定资源标识符

标签 amazon-web-services aws-cloudformation aws-api-gateway

我正在使用 SAM 部署一个简单的 Hello world 应用程序。一个具有一个 API 端点,这将触发一个返回文本 hello world 的 lambda 函数。 我定义了以下资源:

  1. IAM 角色,以便 APIGateway 可以调用 lambda 函数。
  2. AWS::ApiGateway::RestApi
  3. AWS::ApiGateway::资源
  4. AWS::ApiGateway::方法
  5. AWS::Serverless::函数

诚然,我还不知道 2. 和 3. 之间的功能差异。

sam部署期间,我看到以下错误。

ROLLBACK_IN_PROGRESS                              AWS::CloudFormation::Stack                        go-hello-world                                    The following resource(s) failed to create:     
                                                                                                                                                      [HelloWorldAPIResource,                         
                                                                                                                                                      HelloWorldFunctionRole]. Rollback requested by  
                                                                                                                                                      user.                                           
CREATE_FAILED                                     AWS::IAM::Role                                    HelloWorldFunctionRole                            Resource creation cancelled                     
CREATE_FAILED                                     AWS::ApiGateway::Resource                         HelloWorldAPIResource                             Resource handler returned message: "Invalid     
                                                                                                                                                      Resource identifier specified (Service:         
                                                                                                                                                      ApiGateway, Status Code: 404, Request ID:       
                                                                                                                                                      62f34d79-86ab-47fd-85b1-5fbb55071520, Extended  
                                                                                                                                                      Request ID: null)" (RequestToken:               
                                                                                                                                                      9633d7db-7b6d-881b-f54e-ca0114862fd8,           
                                                                                                                                                      HandlerErrorCode: NotFound)

这意味着 AWS::ApiGateway::Resource 未获取对 AWS::ApiGateway::RestApi 的有效引用。

这是我的template.yml中的相关部分

  HelloWorldAPI:
    Type: AWS::ApiGateway::RestApi
    Properties: 
      Name: HelloWorldApi

  HelloWorldAPIResource:
    Type: AWS::ApiGateway::Resource
    Properties:
      RestApiId: !Ref HelloWorldAPI
      ParentId: "/"
      PathPart: hello

总的来说,我对 CloudFormation 和 AWS 都很陌生,非常感谢任何帮助。

最佳答案

应该是:

 ParentId: !GetAtt HelloWorldAPI.RootResourceId

关于amazon-web-services - 无法在 Cloudformation 模板中为 AWS::ApiGateway::Resource 指定资源标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71081939/

相关文章:

java - Amazon Forecast 查询 Java 集成

amazon-web-services - 使用 Google 登录时无法取回 Cognito JWT token

aws-lambda - AWS API Gateway Serverless 验证请求正文并返回错误消息作为响应

amazon-web-services - SNS 的自限流消息长时间未送达会怎样?

java - 如何在 Java 中为 AWS Cognito 用户池中的登录用户以编程方式启用或禁用 MFA?

amazon-web-services - AWS Codepipeline - 一次在多个环境上部署

amazon-web-services - 部署 aws cdk 包时在 IAM 角色中发现重复的标签键

bash - 让 CloudFormation 等待用户数据

aws-api-gateway - 如何在不达到每个 API 授权者限制的情况下在模板之间共享授权者

amazon-web-services - AWS CodePipeline 因 InternalFailure 失败