【问题标题】:Use Nested Stack to separate API gateway error with ouse on other stacks使用嵌套堆栈将 API 网关错误与其他堆栈上的使用分开
【发布时间】:2022-01-19 02:36:58
【问题描述】:

尝试部署嵌套堆栈时出错

主模板

Resources:
  SubStackAPIDev:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: https://c....
      TimeoutInMinutes: 5
      
  SubStacklambdaA:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: https://c....
      TimeoutInMinutes: 5
      Parameters:
        APIDev: !Ref APIGateway
.....

SubStackAPIDev

AWSTemplateFormatVersion: "2010-09-09"

Transform: AWS::Serverless-2016-10-31

....

Outputs:

  APIGateway:
    Description: "API Gateway Reference"
    Value: !Ref APIDev
    Export:
      Name: !Join [":", [!Ref "AWS::StackName", "APIDev"]]

SubStacklambdaA


AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Parameters:
   SecretsManagerName:
     ....
   APIDev:
     Type: string

Resources:
  LambdaFunctionDev:
    Type: AWS::Serverless::Function
    Properties:
      ...
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: ....
            Method: POST
            RestApiId: !Ref APIDev

当我执行 sam package 命令时,控制台返回下一个错误:

sam deploy --force-upload --template-file maintemplate-packaged.yaml --stack-name $STACK_NAME_DEV --region $AWS_REGION --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM

Initiating deployment
=====================
Error: Failed to create changeset for the stack: B2bChannels-dev, An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Unresolved resource dependencies [APIGateway] in the Resources block of the template

如何将 ApGateWay 资源导出到主模板,以发送另一个堆栈?

【问题讨论】:

  • 进展如何?仍然不清楚你能做什么?

标签: amazon-web-services amazon-cloudformation aws-cloudformation-custom-resource nested-stack


【解决方案1】:

要引用嵌套堆栈的输出,您应该使用GetAtt:

  SubStacklambdaA:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: https://c....
      TimeoutInMinutes: 5
      Parameters:
        APIDev: !GetAtt SubStackAPIDev.Outputs.APIGateway

【讨论】:

  • 工作,谢谢!
猜你喜欢
  • 2020-04-14
  • 2019-05-01
  • 1970-01-01
  • 2018-06-21
  • 2016-06-26
  • 2021-05-04
  • 2023-03-23
  • 2014-06-23
  • 1970-01-01
相关资源
最近更新 更多