amazon-web-services - 如何从 CloudFormation 模板中引用 json 配置值?
问题描述
我有以下 cloudformation 模板。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
解决方案
我们可以将该名称提供给 CodePipeline 和输出,方法是将其提取到Mappings 部分。
在下面的示例中,我创建了一个包含StackName
. 要使用这个函数!FindInMap
,我们需要一个两级的 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
推荐阅读
- ansible - 如何在通过命令行运行 ansible 角色时运行标记任务
- flutter - 无法在 Flutter 中使用 Google 电子邮件登录
- sql - 这个 CASE 语句中的 THEN 是做什么的?
- c# - 如何使一个场景中的不同按钮在点击时变为自己指定的场景?
- r - 有没有办法用 R 提取行名?
- python - 如何在 netCDF 文件中按维度过滤数据
- filter - 如何在 ag 网格过滤器中的应用按钮上编写单击事件
- rust - 使用 actix 启动计划任务并访问自己
- kubernetes - 无法通过 minikube 隧道访问应用程序
- java - 迭代器中每个项目的新线程