aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

IRole vs Role types

Open cybergoof opened this issue 7 years ago • 8 comments

I'm having trouble understanding how I would import a role that has already been created, and use that role when creating a lambda function. The Role.import returns a type IRole, which is not assignable to the props when creating a Lambda function.

cybergoof avatar Jan 09 '19 15:01 cybergoof

This is a bug in our Lambda resource. It should accept an IRole and not a role. We are working on cleaning up those APIs.

If you are using typescript, as a temporary workaround, you might be able to add as any when you assign the role and hope for the test

Thanks for reporting!

eladb avatar Jan 09 '19 15:01 eladb

If so, that's a mistake in the Lambda construct, because you're doing it right.

Use a CloudFormation override to work around that for the time being.

rix0rrr avatar Jan 09 '19 16:01 rix0rrr

holy smokes, I was going nuts trying to figure this out. I'm new to Typescript so I couldn't figure out where I was going wrong.

Can you point me to what a CloudFormation override looks like?

cybergoof avatar Jan 09 '19 16:01 cybergoof

Here you go: https://awslabs.github.io/aws-cdk/aws-construct-lib.html#access-the-aws-cloudformation-layer

Elad's suggestion will probably also work btw, and is simpler.

rix0rrr avatar Jan 09 '19 16:01 rix0rrr

as any seems to be working. Thanks for guidance.

cybergoof avatar Jan 09 '19 21:01 cybergoof

Fixed by #1509

eladb avatar Jan 10 '19 11:01 eladb

Looks like this problem has returned. I had the exact same issue, and the "as any" fix seems to work. My error is: Type 'Role' is not assignable to type 'IRole'.

using cdk 1.89.0 (build df7253c)

badfun avatar Feb 11 '21 20:02 badfun

Same problem

aws_lambda.Function(
    role=aws_iam.Role()
)

Pylint sends a warning that 'Role' is not assignable to 'IRole'

entest-hai avatar Jan 27 '22 17:01 entest-hai