簡體   English   中英

使用嵌套堆棧將 API 網關錯誤與其他堆棧上的使用分開

[英]Use Nested Stack to separate API gateway error with ouse on other stacks

嘗試部署嵌套堆棧時出現錯誤是否有 APIGateway 設置,而其他有 lambdas 服務

主模板

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"]]

子棧λA


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 資源導出到主模板,以發送另一個堆棧?

要從嵌套堆棧中引用 output,您應該使用GetAtt

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM