gpt4 book ai didi

amazon-web-services - 如何从 CloudFormation 模板中引用 json 配置值?

转载 作者:行者123 更新时间:2023-12-03 07:24:31 26 4
gpt4 key购买 nike

我有以下云信息模板。 MyCodePipeline 有一个名为 DeployAction 的阶段操作。其配置值之一是 StackName: TestStackName。我应该使用哪个函数从该模板中获取此键 (StackName) 的值 (TestStackName)?我无法使用 !GetAtt,因为 CodePipeline 只有 Version 属性可用。

Resources:

MyCodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt MyCodePipelineRole.Arn
ArtifactStore:
Location: !Ref ArtifactsStore
Type: S3
Stages:
- Name: Source
Actions:
- Name: SourceAction
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: '1'
Provider: GitHub
OutputArtifacts:
- Name: SourceArtifact
Configuration:
Owner: GitHubOwner
Repo: GitHubRepo
PollForSourceChanges: 'false'
Branch: GitHubBranch
OAuthToken: GitHubToken
RunOrder: 1
- Name: Deploy
Actions:
- Name: DeployAction
ActionTypeId:
Category: Deploy
Owner: AWS
Version: '1'
Provider: CloudFormation
Configuration:
ActionMode: CREATE_UPDATE
StackName: TestStackName --> I want to export this name

MyCodePipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'codepipeline.amazonaws.com'
- 'cloudformation.amazonaws.com'
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'

ArtifactsStore:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
VersioningConfiguration:
Status: Enabled
BucketName: my-artifacts-store

Outputs:
TestStackName:
Description: MyCodePipeline.DeployActionStage.Configuration.TestStackName
Value: ????? --> What should I use here to get the TestStackName?
Export:
Name: MyCodePipeline-DeployActionStage-Configuration-TestStackName

最佳答案

我们可以通过将该名称提取到 Mappings section 来为 CodePipeline 和输出提供该名称。 .

在下面的示例中,我创建了一个包含 StackName 的映射结构。使用函数 !FindInMap we need a two-level map ,这就是为什么它看起来有点复杂。请随时提出改进建议:)

Mappings:
MetaInfo:
Names:
StackName: TestStackName

Resources:

MyCodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
...
Stages:
...
- Name: Deploy
Actions:
- Name: DeployAction
...
Configuration:
ActionMode: CREATE_UPDATE
StackName: !FindInMap [MetaInfo, Names, StackName]
...

Outputs:
TestStackName:
Description: MyCodePipeline.DeployActionStage.Configuration.TestStackName
Value: !FindInMap [MetaInfo, Names, StackName]
Export:
Name: MyCodePipeline-DeployActionStage-Configuration-TestStackName

这在 CloudFormation 控制台中提供了以下输出:

Key: TestStackName
Value: TestStackName
Description: MyCodePipeline.DeployActionStage.Configuration.TestStackName
Export name: MyCodePipeline-DeployActionStage-Configuration-TestStackName

关于amazon-web-services - 如何从 CloudFormation 模板中引用 json 配置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60657075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com