-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Unable to generate lambda from cross account s3 bucket #4632
Comments
@ArendAMZN is this still an issue? |
@iliapolo This is still an issue I pushed this to the side to focus on other tasks (even though I still need this to work eventually), but I hit it again with today's task
|
I'm wondering if lambdaFunction.role is actually the thing that needs access to the bucket? Since it's accessing the bucket to create the lambda (rather than execute it) maybe it's using a different role? |
Acking this issue. @ArendAMZN Apologies for the long delay, will get to it this week promptly. |
Hi @ArendAMZN Im trying to figure out the correct way to configure this. Though honestly, i'm not sure this is even possible. Lambda requires the source code bucket to be in the same region as the lambda, it doesn't mention anything about requiring the same account, but that doesn't seem like a stretch to assume. While I investigate this further, I do have a few observations. The following code you posted: var funcCrossPolicy = new iam.PolicyStatement()
funcCrossPolicy.addResources(s3Role.roleArn);
funcCrossPolicy.addActions('sts:AssumeRole');
lambdaFunction.addToRolePolicy(funcCrossPolicy); Doesn't help because the lambda isn't actively attempting to assume any role, so giving it permissions to do so is void. The entity that needs access to the bucket in the different account is actually the lambda service itself, not any specific function. I would try using Unfortunately I don't have a full solution for you just yet, but i wanted to give my input so maybe we can figure this out together :) Also, any chance you elaborate on the use-case for attempting this? Doing cross-account references might not be the best road to follow. Perhaps we can think of a better way to achieve what you need. |
Thank you for looking into it, I'll try using the service principal to see if that fixes things Our use case is very similar to the one detailed here, https://aws.amazon.com/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ We have a tooling account as well as accounts for beta/gamma (or at least that's the final goal). The example deploys cloudformation cross account, and then builds the lambdas within the account. For our use case we'd to pass lambda references within cdk, so waiting for cloud formation to generate the lambdas doesn't work for us Instead we have a code pipeline which works as follows (codecommit -> s3_bucket/beta -> lambda_beta -> s3_bucket/prod -> lambda_prod). The lambdas are in the corresponding beta/prod accounts but the code pipeline and s3_bucket are both in the tooling account. One possible modification is I can have separate beta/prod buckets in the corresponding beta/prod accounts. That way I'm doing as cross account s3 deployment, rather than a cross account lambda build. Do you think that will be easier? |
Here are the details of the 3 approaches I'm considering. Let me know which path you think should be investigated further. I can write more scripts recreating the issue if that would be helpful
I updated the s3 role as follows, but I still get the same bug
As noted earlier, I have a codepipeline (tooling account) and a lambda (beta account). Currently the s3 bucket is in the tooling account. So the pipeline deploys to the s3 bucket, and then the pipeline needs to make a cross account call for the lambda to update from the bucket (reaching back cross account to get the bucket). I can avoid some of this by moving the s3 bucket to the beta account. So the codepipeline needs to deploy cross account to s3, but the lambda doesn't need to pull from cross account to update the code This was an improvement, cdk was able to deploy the codepipeline and lambda stacks, and the codepipeline was able to deploy new code updates cross account to the s3 bucket, but the codepipeline can't the lambda to update it's code from s3 (so the lambda is being triggered cross account, but the operation it needs to do is in the account) Here's the error I get in codebuild when it tries to make the lambda refresh it's code
Here's the piece of that role which I thought would give it permission
And the corresponding role in the beta account
I've previously followed a similar pattern pattern to get my pipeline to access repos cross account, but I'm not sure why it's different for lambda
Since the pipeline can transfer the code to s3 cross account. I can have a separate process trigger on the s3 bucket update and update the lambda (all within the beta account). This way the codepipeline doesn't have to do a cross account call to make the lambda update it's code. I think this would work (although I haven't tested it yet), but I'm not a fan of the pattern. It feels a little excessive to manage an additional "lambda updater" lambda in addition to my service lambdas. Also it hides the status of the deployment from the pipeline (i.e. the pipeline can be green before the deployment is actually complete) |
We figured it out using option #2 The iam role I was using for CodeBuild had assume role permissions to update the code, however I actually needed to perform the assume role operation for that to work (this is different from codepipeline where it automatically assumes the roles) Adding this to my build script fixed it
|
@ArendAMZN Awesome! Happy you got it working Closing this issue |
Hello, I'm trying to define the following setup in CDK
I'm able to generate the s3Stack fine, but when I try to generate the lambdaStack it's unable to reference the s3 bucket cross account
Is this workflow possible in cdk?
Reproduction Steps
Code:
Commands
Error log below is from lambdaStack deployment
Error Log
Environment
The text was updated successfully, but these errors were encountered: