0

假设我在 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 模板中使用的字符串列表中的参数之一?

4

1 回答 1

0

在起草这个问题时,我开始研究 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"
                                }
                            ]
                        }
                    ]
                }
            }
        }
于 2020-11-18T13:27:04.277 回答