IRole vs Role types
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.
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!
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.
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?
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.
as any seems to be working. Thanks for guidance.
Fixed by #1509
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)
Same problem
aws_lambda.Function(
role=aws_iam.Role()
)
Pylint sends a warning that 'Role' is not assignable to 'IRole'