-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
How to deploy CDK app via Lambda #2637
Comments
Since Lambda provides SDK credentials via environment variables, I'm not entirely sure why it would fail. Furthermore: We'd be happy to help you out, but GitHub issues is not a support forum. There are websites much better suited for that, such as StackOverflow. If you could please ask that same question again on StackOverflow and paste the link to it here, we will answer it for you over there. I will now close this issue, feel free to reopen when pasting the StackOverflow link. |
AFAIK, Lambda doesn't provide SDK credentials. The recommended way is to add proper permissions to the Lambda IAM role https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-lambda.html. Setting credentials via env variables is a security concern. Considering the above, this issue is more of a limitation of CDK, not a question. So closing at will seems not caring about your customer which is one of your leadership principles. Having said that, I figured out how to deploy a CDK app via Lambda. And, no, CDK will not work out of the box in Lambda. The following are the changes I had made locally and deployed to Lambda. Overrode
Here is how I used
Copied over the same command line parsing function from
Note the last
That's to make sure which app to use as well as override the staging directory since Lambda allows to write only to Finally had to fix this line https://github.com/awslabs/aws-cdk/blob/master/packages/aws-cdk/lib/api/util/sdk.ts#L71:
When running from Lambda
The fixed code is:
As a reminder, because I didn't appreciate your response, this was not a question but a report that a certain functionality is not supported. If you reopen, I will, perhaps, create a PR to make CDK work from within Lambda. |
Hi @rix0rrr, as requested, here is a StackOverflow question relating to this issue. I think there's a valid use-case for wanting to have Lambdas able to call the CDK that is described in that question: https://stackoverflow.com/questions/58781821/is-it-possible-to-deploy-aws-cdk-stacks-from-within-a-lambda. It's to do with working around the limitation of AWS CodePipeline only supporting a single Git branch, so using a Lambda to create Pipelines dynamically in response to GitHub events indicating the creation or repos and branches. It seems a bit dirty to me to have to get STS credentials via @kadishmal, please would you mind considering reopening this issue (unless you feel that there is a sensible workaround, in which case please would you mind letting me know what that workaround is)? If I'm missing something and there is a simple solution then I'd be very happy to see it posted to that SO question, thanks! |
@kadishmal can you please provide an example how to provision CDK App from Lambda? |
This issue needs to be reopened and resolved - if nothing else with an example. There are numerouse examples of Lambdas deploying CF templates in YAML or JSON. We need that same functionality, but from the CDK perspective - that a Lambda could deploy a CDK Stack construct. This is a perfect example of what we should be able to achieve: Quickstart example |
@MHacker9404 @denizhoxha I created a repo with an example of how I put CDK into Lambda layer and used it with a Lambda to deploy and destroy a bucket. The size of lambda can become an issue as the maximum is 250mb. |
Dude – that’s awesome – thanks.
No experience with Terraform so this will take a little to digest….
|
I have written an article about running AWS CDK inside a Lambda function. Maybe it will be useful for you: https://raszpel.medium.com/running-aws-cdk-from-a-lambda-function-9369d3daba57 or https://dev.to/mraszplewicz/running-aws-cdk-from-a-lambda-function-3502 And the Github repo: https://github.com/devopsbox-io/example-cdk-from-lambda/ |
Awsum – thank you. It’[l take a little digging on my part, since I don’t know Java or the tools, but I look forward checking this out…..
From: Maciej Raszplewicz <[email protected]>
Sent: 12 November, 2020 05:30
To: aws/aws-cdk <[email protected]>
Cc: Phil Boyd <[email protected]>; Mention <[email protected]>
Subject: Re: [aws/aws-cdk] How to deploy CDK app via Lambda (#2637)
I have written an article about running AWS CDK inside a Lambda function. Maybe it will be useful for you: https://raszpel.medium.com/running-aws-cdk-from-a-lambda-function-9369d3daba57 or https://dev.to/mraszplewicz/running-aws-cdk-from-a-lambda-function-3502
And the Github repo: https://github.com/devopsbox-io/example-cdk-from-lambda/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#2637 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AA75SHEEZNQ3SKZIUVNEVATSPO2JJANCNFSM4HPSZEJQ>.
|
Another example here https://github.com/imyoungyang/cdk-in-lambda |
I created this repository which uses a 5 minute approach with Gradle & Docker to install CDK in a targeted location and mounts the Lambda Layer zipfile on your local system which you can use directly to manually upload in the AWS console or use i.e. with CDK. An example Lambda handler function with NodeJS runtime and with the layer attached can look something like:
|
Hi,
I think this is an unsupported use case for CDK. I am trying to deploy the CDK app via Lambda. The goal is for the Lambda function to call
cdk deploy
and get the application, included together with the Lambda code, deployed.Currently, calling
cdk deploy
via the Node'sexec
command fails due to missing AWS credentials. Ideally, the same role that is used to execute the Lambda function should be reused. In my case this function has all the permissions to deploy a CFN template that the underlying CDK generates.I tried to extract the deployment related code out of the
aws-cdk
package and call it directly, but found out that it depends on the credential provider which tries to find the credentials either in the env variables or config files.Is there a way to bypass this credentials check and let it just call the APIs to do the job?
Thanks.
The text was updated successfully, but these errors were encountered: