Home > OS >  Adding the custom policy to the Role (taskRole)
Adding the custom policy to the Role (taskRole)

Time:04-26

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);

CodePudding user response:

I think you should be using attachInlinePolicy, instead of addToResourcePolicy.

  • Related