Skip to content
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

Add no-handler-update option to omit updating the handler on lambda #1

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ claudia update {OPTIONS}
* _Defaults to_: current directory
* `--config`: (_optional_) Config file containing the resource names
* _Defaults to_: claudia.json
* `--handler`: (_optional_) Main function for Lambda to execute, as module.function
* _For example_: if it is in the main.js file and exported as router, this would be main.router
* `--no-handler-update`: (_optional_) Do not update the handler in Lambda. This can be used in conjunction with `--handler`
when you want to validate a handler function name different from what is configured in Lambda.
This is useful if additional layers wrap the handler (e.g., [Datadog](https://docs.datadoghq.com/serverless/installation/nodejs/?tab=custom)).
* _Defaults to_: updates handler if provided via `--handler` or ends in `'router'`
* `--timeout`: (_optional_) The function execution time, in seconds, at which AWS Lambda should terminate the function
* `--runtime`: (_optional_) Node.js runtime to use. For supported values, see
http://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html
Expand Down
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions spec/update-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ describe('update', () => {
]);
}).then(done, done.fail);
});

describe('handler option support', () => {
beforeEach(done => {
fsUtil.copy('spec/test-projects/hello-world', workingdir, true);
Expand Down Expand Up @@ -656,9 +657,16 @@ describe('update', () => {
.then(configuration => expect(configuration.Handler).toEqual('main.handler'))
.then(done, done.fail);
});

it('does not update AWS handler name with --no-handler-update', done => {
fsUtil.copy('spec/test-projects/api-gw-echo', workingdir, true);
underTest({source: workingdir, version: 'new', handler: 'main.proxyRouter', 'handler-update': false})
.then(() => getLambdaConfiguration())
.then(configuration => expect(configuration.Handler).toEqual('main.handler'))// TODO: this may be old
.then(() => getLambdaConfiguration('new'))
.then(configuration => expect(configuration.Handler).toEqual('main.handler'))
.then(done, done.fail);
});
});

describe('timeout option support', () => {
beforeEach(done => {
fsUtil.copy('spec/test-projects/hello-world', workingdir, true);
Expand Down
5 changes: 3 additions & 2 deletions src/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ module.exports = function update(options, optionalLogger) {
.then(() => lambda.getFunctionConfiguration({FunctionName: lambdaConfig.name}).promise())
.then(result => {
functionConfig = result;
requiresHandlerUpdate = apiConfig && apiConfig.id && /\.router$/.test(functionConfig.Handler);
const explicitNoUpdateHandler = options['handler-update'] === false;
requiresHandlerUpdate = !explicitNoUpdateHandler && apiConfig && apiConfig.id && /\.router$/.test(functionConfig.Handler);
if (requiresHandlerUpdate) {
functionConfig.Handler = functionConfig.Handler.replace(/\.router$/, '.proxyRouter');
} else if (options.handler) {
functionConfig.Handler = options.handler;
requiresHandlerUpdate = true;
requiresHandlerUpdate = !explicitNoUpdateHandler;
}
})
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/wait-until-not-pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports = function waitUntilNotPending(lambda, functionName, timeout, ret
() => {
return lambda.getFunctionConfiguration({FunctionName: functionName}).promise()
.then(result => {
if (result.state === 'Failed') {
if (result.State === 'Failed') {
throw `Lambda resource update failed`;
}
if (result.state === 'Pending') {
if (result.State === 'Pending') {
throw 'Pending';
}
if (result.LastUpdateStatus === 'InProgress') {
Expand Down