如何在 CloudFormation 模板中使用来自 SSM StringList 的值?

How can I use a value from an SSM StringList in a CloudFormation template?

假设我在 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"
                    ]
                },
                ...

但显然这将 return 完整的字符串列表,而不仅仅是 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"]
  • 将其拆分成一个列表
  • select 第一个值为 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"
                                }
                            ]
                        }
                    ]
                }
            }
        }