简体   繁体   English

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

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

Let's assume I have a parameter in the SSM ParameterStore.假设我在 SSM ParameterStore 中有一个参数。 The parameter has a StringList as value and describes a service, such as (bucket_name, request_url)该参数有一个 StringList 作为值并描述一个服务,例如 (bucket_name, request_url)

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

Now, in CloudFormation I want to define the name of my bucket from this stringlist.现在,在 CloudFormation 中,我想从这个字符串列表中定义我的存储桶的名称。

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

But obviously this will return the full stringlist, not just bucket_name_A但显然这将返回完整的bucket_name_A ,而不仅仅是bucket_name_A

How can I access one of the parameters in the stringlist to be used in the CloudFormation template?如何访问要在 CloudFormation 模板中使用的字符串列表中的参数之一?

Whilst drafting this question I started looking into the Fn:: methods在起草这个问题时,我开始研究 Fn:: 方法

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

and I got an idea:我有一个想法:

The stringlist is: "bucket_name_A, https://www.request.com/A" "bucket_name_A, https://www.request.com/A"是: "bucket_name_A, https://www.request.com/A" : "bucket_name_A, https://www.request.com/A"

  • retrieve the stringlist value with Fn::GetAtt => "bucket_name_A, https://www.request.com/A"使用Fn::GetAtt => "bucket_name_A, https://www.request.com/A"检索Fn::GetAtt列表值
  • split it into a list with Fn::Split => ["bucket_name_A", "https://www.request.com/A"]使用Fn::Split => ["bucket_name_A", "https://www.request.com/A"]将其拆分为一个列表
  • select the first value with Fn::Select => "bucket_name_A"使用Fn::Select => "bucket_name_A"选择第一个值

and it works!它有效! Here below is the cloudformation template:下面是cloudformation模板:

SSM Parameter Store : 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 : 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"
                                }
                            ]
                        }
                    ]
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 cloudformation 模板中使用 AWS SSM 的 StringList 值 - How to use StringList value of AWS SSM in cloudformation template 如何在 Cloudformation 模板条件中使用 AWS SSM 参数存储值? - How to use AWS SSM parameter store values in Cloudformation template conditionals? AWS SSM 运行命令:使用 Cloudformation 模板中的当前帐号 - AWS SSM Run command : use the current account number from a Cloudformation Template 如何在CloudFormation模板中使用来自其他AWS账户的AssumeRole? - How can I use AssumeRole from another AWS account in a CloudFormation template? 如何将密钥从我的桌面导入到 cloudformation 模板? - How can I import a key from my desktop to the cloudformation template? 如何在 CloudFormation 中使用预定义的 SSM Windows 补丁基线 - How to use pre-defined SSM Windows patch baselines in CloudFormation 如何使用 CloudFormation 从别名获取 AWS SSM 密钥 Arn? - How to get an AWS SSM Key Arn from an Alias using CloudFormation? 我可以从 AWS python lambda 更新 ssm 参数值吗 - Can I update ssm parameter value from AWS python lambda 如何将 ssh 与 AWS ssm 会话和多配置文件一起使用? - How can I use ssh with AWS ssm sessions and multi profiles? 如何正确地将SSM参数存储StringList映射到Lambda VpcConfig节 - How to properly map an SSM parameter store StringList to a Lambda VpcConfig section
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM