Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRole vs Role types #1506

Closed
cybergoof opened this issue Jan 9, 2019 · 8 comments
Closed

IRole vs Role types #1506

cybergoof opened this issue Jan 9, 2019 · 8 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug.

Comments

@cybergoof
Copy link

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.

@eladb
Copy link
Contributor

eladb commented Jan 9, 2019

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 eladb added bug This issue is a bug. @aws-cdk/aws-lambda Related to AWS Lambda labels Jan 9, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 9, 2019

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.

@cybergoof
Copy link
Author

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?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 9, 2019

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.

@cybergoof
Copy link
Author

as any seems to be working. Thanks for guidance.

@eladb
Copy link
Contributor

eladb commented Jan 10, 2019

Fixed by #1509

@badfun
Copy link
Contributor

badfun commented Feb 11, 2021

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)

@entest-hai
Copy link

Same problem

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants