Skip to content

Commit df34e3c

Browse files
authored
Merge pull request #75 from richarddd/add-warmup-client-context
Add Client Context to invoke params
2 parents a9b8c50 + 77657b9 commit df34e3c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ module.exports.lambdaToWarm = function(event, context, callback) {
202202
... add lambda logic after
203203
}
204204
```
205+
You can also check for the warmp event using the `context` variable. This could be useful if you are handling the raw input and output streams:
206+
207+
```javascript
208+
...
209+
210+
if(context.custom.source === 'serverless-plugin-warmup'){
211+
console.log('WarmUP - Lambda is warm!')
212+
return callback(null, 'Lambda is warm!')
213+
}
214+
215+
...
216+
```
217+
218+
205219

206220
* All done! WarmUP will run on SLS `deploy` and `package` commands
207221

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class WarmUP {
5757
this.serverless.service.provider.region ||
5858
(this.serverless.service.defaults && this.serverless.service.defaults.region) ||
5959
'us-east-1'
60+
6061
this.custom = this.serverless.service.custom
6162

6263
this.configPlugin()
@@ -104,6 +105,7 @@ class WarmUP {
104105
this.pathFolder = this.getPath(this.folderName)
105106
this.pathFile = this.pathFolder + '/index.js'
106107
this.pathHandler = this.folderName + '/index.warmUp'
108+
this.payload = JSON.stringify({ source: 'serverless-plugin-warmup' })
107109

108110
/** Default options */
109111
this.warmup = {
@@ -271,11 +273,12 @@ module.exports.warmUp = async (event, context, callback) => {
271273
console.log("Warm Up Start");
272274
const invokes = await Promise.all(functionNames.map(async (functionName) => {
273275
const params = {
276+
ClientContext: "${Buffer.from(`{"custom":${this.payload}}`).toString('base64')}",
274277
FunctionName: functionName,
275278
InvocationType: "RequestResponse",
276279
LogType: "None",
277280
Qualifier: process.env.SERVERLESS_ALIAS || "$LATEST",
278-
Payload: '${JSON.stringify({ source: 'serverless-plugin-warmup' })}'
281+
Payload: ${this.payload}
279282
};
280283
281284
try {

0 commit comments

Comments
 (0)