任何人都可以帮助我将此CloudFormation“转换”为CDK(Java或Java)吗?我正在尝试做,但这是我第一次与CDK合作,我不确定该怎么做。我真的很喜欢。
FargateTaskExecutionServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: AmazonECSTaskExecutionRolePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- 'ecr:GetAuthorizationToken'
- 'ecr:BatchCheckLayerAvailability'
- 'ecr:GetDownloadUrlForLayer'
- 'ecr:BatchGetImage'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
您应参考API reference document以获得清晰的图像。有此类用例的示例。
但是,由于您已经在这里问过,并且我的手很想为您提供答案,所以这里使用TypeScript实现:
import { Role, ServicePrincipal, PolicyStatement, Effect } from '@aws-cdk/aws-iam';
....
....
const ecsFargateServiceRole = new Role(this, 'FargateTaskExecutionServiceRole', {
assumedBy: new ServicePrincipal('ecs-tasks.amazonaws.com')
});
ecsFargateServiceRole.addToPolicy(
new PolicyStatement({
effect: Effect.ALLOW,
resources: ['*'],
actions: [
'ecr:GetAuthorizationToken',
'ecr:BatchCheckLayerAvailability',
'ecr:GetDownloadUrlForLayer',
'ecr:BatchGetImage',
'logs:CreateLogStream',
'logs:PutLogEvents'
]
})
);
....
....
请注意,为简洁起见,我已排除了Construct的构造函数。