作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下云信息模板。 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/
我是一名优秀的程序员,十分优秀!