gpt4 book ai didi

amazon-web-services - 如何在 CloudFormation 模板中使用 SSM StringList 中的值?

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

假设我在 SSM ParameterStore 中有一个参数。该参数以 StringList 作为值,描述一个服务,例如 (bucket_name, request_url)

“serviceA”=“bucket_name_A,https://www.request.com/A”

现在,在 CloudFormation 中,我想从此字符串列表中定义我的存储桶的名称。

"S3FTSE100Intraday1min": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": {
"Fn::GetAtt": [
"My_SSM_ParameterStore_Logical_ID",
"Value"
]
},
...

但显然这将返回完整的字符串列表,而不仅仅是bucket_name_A

如何访问要在 CloudFormation 模板中使用的字符串列表中的参数之一?

最佳答案

在起草这个问题时,我开始研究 Fn::方法

(来源:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-split.html)

我有了一个想法:

字符串列表为:"bucket_name_A, https://www.request.com/A"

  • 使用 Fn::GetAtt 检索字符串列表值=> "bucket_name_A, https://www.request.com/A"
  • 将其拆分为 Fn::Split 的列表=> ["bucket_name_A", "https://www.request.com/A"]
  • 选择第一个值 Fn::Select => "bucket_name_A"

并且它有效!下面是cloudformation模板:

SSM Parameter Store :

"SSMTestBucketName": {
"Type": "AWS::SSM::Parameter",
"Properties": {
"Name": "StringList_Test_Bucket_Name",
"Type": "StringList",
"Value": "test-ssm-stringlist-bucket, https://www.requesturl.com"
}
}

S3 Bucket :

"S3TestBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": {
"Fn::Select": [
"0",
{
"Fn::Split": [
",",
{
"Fn::GetAtt": [
"SSMTestBucketName",
"Value"
]
}
]
}
]
},
"BucketEncryption": {
"ServerSideEncryptionConfiguration": [
{
"ServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}
]
},
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
},
"LifecycleConfiguration": {
"Rules": [
{
"Status": "Enabled",
"Transitions": [
{
"TransitionInDays": "30",
"StorageClass": "STANDARD_IA"
}
]
}
]
}
}
}

关于amazon-web-services - 如何在 CloudFormation 模板中使用 SSM StringList 中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64894020/

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