-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(cli): support hotswapping Lambda functions with inline code #18408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts
Show resolved
Hide resolved
packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @tmokmss! A few minor comments before we merge this in 🙂.
// We must create a zip package containing a file with the inline code | ||
const rawZipFile = await evaluateCfnTemplate.evaluateCfnExpression(updatedProp.newValue[newPropName]); | ||
// file extension must be chosen depending on the runtime | ||
const runtime: string = await evaluateCfnTemplate.evaluateCfnExpression(change.newValue.Properties!.Runtime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the !
really required? Can we go without it?
const runtime: string = await evaluateCfnTemplate.evaluateCfnExpression(change.newValue.Properties!.Runtime); | |
const runtime: string = await evaluateCfnTemplate.evaluateCfnExpression(change.newValue.Properties.Runtime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's call this variable functionRuntime
, just to make it's very clear what runtime we are talking about here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties
is possibly undefined so we need to care it.
aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts
Lines 475 to 480 in c7c51de
export interface Resource { | |
Type: string; | |
Properties?: { [name: string]: any }; | |
[key: string]: any; | |
} |
I replaced !
to ?
to care when runtime is undefined, c.f. s3-bucket-deployments.ts
(idk if there's such a case though)
aws-cdk/packages/aws-cdk/lib/api/hotswap/s3-bucket-deployments.ts
Lines 25 to 28 in c7c51de
const functionName = await evaluateCfnTemplate.evaluateCfnExpression(change.newValue.Properties?.ServiceToken); | |
if (!functionName) { | |
return ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT; | |
} |
packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk/test/api/hotswap/lambda-functions-inline-hotswap-deployments.test.ts
Show resolved
Hide resolved
Pull request has been modified.
@skinny85 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @tmokmss, thanks for the contribution!
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…#18408) Similarly to aws#18319, this PR supports hotswap of Lambda functions that use `InlineCode`. `InlineCode` uses [CloudFormation `ZipFile` feature](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#:~:text=requires%3A%20No%20interruption-,ZipFile,-\(Node.js%20and). To emulate its behavior, we create a zip file of the provided inline code with its filename `index.js` or `index.py` according to the runtime (CFn only supports python or nodejs for ZipFile), and pass the file's binary buffer to Lambda API. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Similarly to #18319, this PR supports hotswap of Lambda functions that use
InlineCode
.InlineCode
uses CloudFormationZipFile
feature. To emulate its behavior, we create a zip file of the provided inline code with its filenameindex.js
orindex.py
according to the runtime (CFn only supports python or nodejs for ZipFile), and pass the file's binary buffer to Lambda API.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license