Isa*_*aac 2 amazon-web-services amazon-ecs aws-cloudformation aws-cdk
在AWS控制台中创建基于EC2的ECS集群时,您可以指定容器实例角色:
但是,创建集群后,我看不到任何方法来查看哪个角色附加到集群。
此外,在使用cli或在Cloudformation(或者扩展为 CDK)中创建集群时,我没有看到任何指定容器实例角色的方法。
我的问题有两个:
控制台会让您相信它是 ECS 属性,但实际上它只是一个称为“IAM 实例配置文件”的 EC2 属性。您必须通过在可在 AutoScaling 组内使用的资源上设置IamInstanceProfile 属性AWS::EC2::Instance来指定此角色,甚至更好。AWS::EC2::LaunchTemplate需要注意的是,您还无法直接将角色添加到该属性中,您需要创建AWS::IAM::InstanceProfile第一个角色,如下所示:
EcsInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- ecsInstanceRole
Run Code Online (Sandbox Code Playgroud)
为了完整起见,以下是在启动模板中设置该属性的方法:
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
IamInstanceProfile:
Arn: !GetAtt EcsInstanceProfile.Arn
...
Run Code Online (Sandbox Code Playgroud)