【发布时间】:2021-07-15 11:02:54
【问题描述】:
我对使用 CDK 很陌生,我正在尝试为我的启动配置生成 user_data。但是遇到问题...从这里获取用户数据并尝试将其调整为我的 CDK 模板:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-ecs.html#quickref-ecs-example-1.yaml
这是我的代码
const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc: existingVpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.XLARGE),
machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
minCapacity: 3,
desiredCapacity: 3,
maxCapacity: 10,
instanceMonitoring: autoscaling.Monitoring.DETAILED,
});
// Create an ECS cluster
const cluster = new ecs.Cluster(this, 'Cluster', {
vpc: existingVpc,
clusterName: envName,
});
asg.addUserData(`
echo ECS_CLUSTER=${cluster.clusterName} >> /etc/ecs/ecs.config
yum install -y aws-cfn-bootstrap
/opt/aws/bin/cfn-signal -e $? --stack ${this.stackName} --resource ${asg} --region ${this.region}
`
)
这会生成以下用户数据
UserData:
Fn::Base64:
Fn::Join:
- ""
- - |-
#!/bin/bash
echo ECS_CLUSTER=
- Ref: ClusterEB0386A7
- |2
>> /etc/ecs/ecs.config
yum install -y aws-cfn-bootstrap
/opt/aws/bin/cfn-signal -e $? --stack CdkClusterStack --resource CdkClusterStack/ASG --region eu-west-1
这让我很困惑。 cluster.clusterName 根本不返回集群名称,而是返回底层集群资源的 Ref。
对于 ASG,生成了以下内容,我想这里而不是我目前得到的 CdkClusterStack/ASG 我需要 ASG46ED3070
ASG46ED3070:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MaxSize: "10"
MinSize: "3"
DesiredCapacity: "3"
.... more stuff ....
请指教!
【问题讨论】:
标签: amazon-web-services aws-cdk