aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.6k stars 3.9k forks source link

(stepfunctions-tasks): support bring your own role for Lambda created by EvaluteExpression #29350

Open lagroujl opened 7 months ago

lagroujl commented 7 months ago

Describe the feature

EvaluateExpression creates a singleton Lambda function. For customers that requiring strict monitoring of the IAM roles in their AWS accounts, the auto-generated roles may not fit their requirements. This can be alleviated by providing the ability to bring their own role

Use Case

Customers with strict controls over IAM roles that need more precise control of the IAM roles created in their AWS accounts

Proposed Solution

Other Information

No response

Acknowledgements

CDK version used

2.130.0

Environment details (OS name and version, etc.)

n/a

lagroujl commented 7 months ago

I had already created a pull request for this. But I jumped in when I thought this was a little simpler than it turned out to be. So I thought a better approach was to create an issue/socialize the change & implementation.

the main issue is getting around the fact that EvaluateExpression uses SingletonFunction. Which is fine for the existing implementation, but adding the role property can cause some confusing behavior if its not implemented correctly. The first thing I noticed was the UUID is based only on the nodejs version, so you need to also take into account the role passed in, or the first instance of SingletonFunction evaluated will prevent other roles from being used.

pahud commented 7 months ago

Makes sense.

Before we have the fix I guess you probably can find out the IAM role of the lambda SingletonFunction and override it with your existing one. You probably can modify my sample to fit your needs:

pahud commented 7 months ago

While workaround is possible, we still welcome and appreciate any pull requests to address this.

lagroujl commented 7 months ago

https://github.com/aws/aws-cdk/issues/29212 is also a good example of what can go wrong. With my implementation, if you were to change the role between deployments, any currently running workflows could fail.

lagroujl commented 7 months ago

@pahud I created this PR: https://github.com/aws/aws-cdk/pull/29288. I'm just curious if I could get some feedback to see if this is the right approach or the CDK even wants to add this feature.

I don't think that your sample is really sufficient. One of the things my customer needs is the ability to use roles that are imported into the stack. Some modification to your sample would let them rename the role that is created, but I don't think it would be possible or that easy to use an imported role.