-
Notifications
You must be signed in to change notification settings - Fork 377
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 parameter to power-tune only cold starts #206
Changes from 15 commits
efd6ad0
89a255b
711e37d
4720586
f70677d
0445f32
4d8f554
f6d7ad1
32f9533
c0dd5ff
dd14172
c0192ec
5a2e515
93802fd
aa85838
1656b7e
79bb3b8
3c4b5d6
69edf22
6b9c85d
331de58
aad097c
2a547a6
4b58451
9a9b243
1979fb6
446fff2
e8b7d17
71aa0cb
40c221b
6f001da
940ecd8
000cd74
797f89c
355ea6f
18a8a65
aba4d63
103786c
38f5c96
d837b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const utils = require('./utils'); | ||
|
||
|
||
module.exports.handler = async(event, context) => { | ||
const {iterator, aliases, currConfig, lambdaARN} = validateInputs(event); | ||
const {envVars} = await utils.getLambdaPower(lambdaARN); | ||
// Alias may not exist when we are reverting the Lambda function to its original configuration | ||
if (typeof currConfig.alias !== 'undefined'){ | ||
envVars.LambdaPowerTuningForceColdStart = currConfig.alias; | ||
mriccia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
delete envVars.LambdaPowerTuningForceColdStart; | ||
} | ||
|
||
// publish version & assign alias (if present) | ||
await utils.createPowerConfiguration(lambdaARN, currConfig.powerValue, currConfig.alias, envVars); | ||
if (typeof currConfig.alias !== 'undefined') { | ||
// keep track of all aliases | ||
aliases.push(currConfig.alias); | ||
} | ||
|
||
// update iterator | ||
iterator.index++; | ||
iterator.continue = (iterator.index < iterator.count); | ||
if (!iterator.continue) { | ||
delete event.powerValues.initConfigurations; | ||
} | ||
event.powerValues.aliases = aliases; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something seems confusing here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, figured this is because of the result path of the Initializer function. As commented below, I would rename that result path to make this easier to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, instead of modifying |
||
return event.powerValues; | ||
}; | ||
function validateInputs(event) { | ||
if (!event.lambdaARN) { | ||
throw new Error('Missing or empty lambdaARN'); | ||
} | ||
const lambdaARN = event.lambdaARN; | ||
if (!(event.powerValues && event.powerValues.iterator && event.powerValues.initConfigurations)){ | ||
throw new Error('Invalid iterator for initialization'); | ||
} | ||
const iterator = event.powerValues.iterator; | ||
if (!(iterator.index >= 0 && iterator.index < iterator.count)){ | ||
throw new Error(`Invalid iterator index: ${iterator.index}`); | ||
} | ||
const initConfigurations = event.powerValues.initConfigurations; | ||
const aliases = event.powerValues.aliases || []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be empty the first time Publisher is invoked, right? |
||
const currIdx = iterator.index; | ||
const currConfig = initConfigurations[currIdx]; | ||
if (!(currConfig && currConfig.powerValue)){ | ||
throw new Error(`Invalid init configuration: ${currConfig}`); | ||
} | ||
return {iterator, aliases, currConfig, lambdaARN}; | ||
} |
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.
Looking at what the Initializer is doing (very similarly), I would consider merging utils.getLambdaPower and utils.getLambdaConfig since they are both using
GetFunctionConfigurationCommand
and they're simply retrieving different fields from the result.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.
Not blocking for this PR - just a reminder for myself in the future :)