question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda props does not allow you to bring your own Role

See original GitHub issue

I don’t know how to attach my own role to a Lambda function – the props won’t accept one, and the .role attribute is read-only. I usually write a dedicated role to associate with any Lambda function, or reference one that has been created independently. ‘@aws-cdk/lambdaLambda seems to be hard-wired to provide its own service role?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

12reactions
bgdnlpcommented, Jun 21, 2019

For others that arrive here looking for how to create the IRole object needed, use the from_role_arn method of the Role class in aws_cdk.aws_iam.

Example Python code:

from aws_cdk import aws_iam

role = aws_iam.Role.from_role_arn(self, 'role_id', 'arn:aws:iam::123456789012:role/myrole')

will create an IRole object that can be passed as a parameter to Lambda Function.

0reactions
silverspasecommented, Mar 21, 2021

I didn’t managed to add role during lambda creation, but next code gives to lambda access to external role, created in another CDK:

lambdaFn.addToRolePolicy(new iam.PolicyStatement({
      effect: iam.Effect.ALLOW,
      actions: [ "sts:AssumeRole" ],
      resources: [externalRoleArn]
    }))
Read more comments on GitHub >

github_iconTop Results From Across the Web

interface FunctionProps · AWS CDK
Whether to allow the Lambda to send all network traffic. allowPublicSubnet? boolean, Lambda Functions in a public subnet can NOT access the internet....
Read more >
Specifying a custom role for lambda with the AWS CDK
A Lambda already comes with an execution role, and it already has the basic execution permissions. If you want to add additional permissions ......
Read more >
How to add permissions to Lambda Functions in AWS CDK
In order to add permissions to a Lambda Function, we have to attach a policy to the function's role. The code for this...
Read more >
How to Create AWS CDK Lambda Functions? 4 Easy Steps
You can design your code into AWS CDK Lambda functions that process ... you can also provide your own IAM role, though permission...
Read more >
Hello Lambda | AWS CDK Workshop
You 've hit ${event.path}\n` }; }; This is a simple Lambda function which ... Save your code, and let's take a quick look...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found