Adding the custom policy to the Role (taskRole)

Viewed 25

I am trying to add policystatement to task.

What I made now is like this below.

const myBucketPolicy = new iam.PolicyStatement({
  effect: iam.Effect.ALLOW,
  actions: [
    "s3:PutObject*"
  ],
  resources: [
    up_bk.bucketArn,
    up_bk.bucketArn + "/*"
  ],
});

try to add this to the fargate taskrole.

props!.taskDefinitionAdmin.taskRole.addToResourcePolicy(myBucketPolicy);

However, this error comes.

Property 'addToResourcePolicy' does not exist on type 'IRole'.

So basically, my idea is wrong.

How can I add the custom policy to the role?


Solution using attachInlinePolicy

const pushacl = new iam.PolicyStatement({
  effect: iam.Effect.ALLOW,
  actions: [
    "s3:PutObject*"
  ],
  resources: [
    "*"
  ],
});

const pushaclpolicy = new iam.Policy(this, 'pushs3acl-policy', {
  statements: [pushacl]
});

taskDefinitionAdmin.taskRole.attachInlinePolicy(pushaclpolicy);
1 Answers
Related