Harsha
Harsha

Reputation: 363

Passing code from CodePipeline to PythonFunction

I'm trying to create a CDK app that will deploy a pipeline-stack and a lambda-stack. Similar to the tutorial here. I'm trying to implement a basic CI/CD application that is triggered with every push to a Github Enterprise Repo.

I chose to use PythonFunction from (@aws-cdk/aws-lambda-python) instead of function from @aws-cdk/aws-lambda because PythonFunction builds the dependencies from requirements.txt. I have various lambdas that use different packages (like awswrangler, pandas, requests, etc.).

But, PythonFunction does not support CfnParametersCode (Where the code is passed through CDK instead of being read from an asset).

I apologize if I'm missing something obvious, I just started working with AWS CDK last week.

Upvotes: 1

Views: 670

Answers (2)

Imanuel Richter
Imanuel Richter

Reputation: 11

First of all I would recommend to take a look at pipelines.CdkPipeline which is able to deal with Assets. That means you can directly use lambda.Code.from_asset instead of overriding CfnParametersCode in the Pipeline.

Regarding your other question, you can deal with the requirements by installing them into your lambda folder during the build step with: pip install -r requirements.txt -t .

Upvotes: 1

saart
saart

Reputation: 402

CfnParametersCode gives you the ability to upload your code from an S3 file. You can do the same via lambda.Code.fromBucket.

Taking your link from the third point (https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda#bundling-asset-code) You just need to use lambda.Code.fromBucket instead of code: lambda.Code.fromAsset. Docs can be found here: https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda

Upvotes: 0

Related Questions