【发布时间】:2019-12-28 06:05:12
【问题描述】:
我正在尝试使用 AWS CloudFormation 模板创建一个 EC2 实例,其中包含使用模板中的动态引用和跨堆栈引用生成的一些用户数据。 AWS Systems Manager Parameter Store 中有一个参数存储在Name:/MyCustomParameter 和Value:Test1。
这个想法是将参数传递给模板堆栈(堆栈A),该堆栈引用另一个云形成堆栈(堆栈B)。堆栈 B 使用引用“StackB::ParameterStoreName”导出一个变量。堆栈 A 使用 Fn::ImportValue: 'StackB::ParameterStoreName' 获取它的值,以便它可以与动态引用方法一起使用,以使用 {{resolve:ssm:/MyCustomParameter:1}} 从 AWS SSM Parameter Store 获取它的值,并将其值传递给模板中的 UserData 字段。在此用例中尝试使用嵌套的 Fn::Sub: 函数时,我遇到了困难。
我尝试删除 | 管道并使用带有转义换行符的双引号,但这不起作用。
我还尝试使用不同类型的资源,它的属性在哪里起作用。下面是一个有效的代码示例。
Resources:
TestBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName:
Fn::Sub:
- '${SSMParameterValue}-12345'
- SSMParameterValue:
Fn::Sub:
- '{{resolve:ssm:${SSMParameterName}:1}}'
- SSMParameterName:
Fn::ImportValue:
!Sub '${CustomStack}::ParameterStoreName'
以下是我当前代码的摘录:
Parameters:
CustomStack:
Type: "String"
Default: "StackB"
Resources:
MyCustomInstance:
Type: 'AWS::EC2::Instance'
Properties:
UserData:
Fn::Base64:
Fn::Sub:
- |
#!/bin/bash -e
#
# Bootstrap and join the cluster
/etc/eks/bootstrap.sh --b64-cluster-ca '${SSMParameterValue}' --apiserver-endpoint '${Endpoint}' '${ClusterName}'"
- SSMParameterValue:
Fn::Sub:
- '{{resolve:ssm:/${SSMParameterName}:1}}'
- SSMParameterName:
Fn::ImportValue:
!Sub '${CustomStack}::ParameterStoreName'
Endpoint:
Fn::ImportValue:
!Sub '${CustomStack}::Endpoint'
ClusterName:
Fn::ImportValue:
!Sub '${CustomStack}::ClusterStackName'
电流输出:
#!/bin/bash -e
#
# Bootstrap and join the cluster
/etc/eks/bootstrap.sh --b64-cluster-ca `{{resolve:ssm:MyCustomParameter:1}}` --apiserver-endpoint 'https://04F1597P0HJ11FQ54K0YFM9P19.gr7.us-east-1.eks.amazonaws.com' 'eks-cluster-1'
预期输出:
#!/bin/bash -e
#
# Bootstrap and join the cluster
/etc/eks/bootstrap.sh --b64-cluster-ca `Test1` --apiserver-endpoint 'https://04F1597P0HJ11FQ54K0YFM9P19.gr7.us-east-1.eks.amazonaws.com' 'eks-cluster-1'
【问题讨论】:
标签: amazon-cloudformation aws-cli amazon-eks