Instantly share code, notes, and snippets.

@kmiyabbm /handler.js
Last active Nov 20, 2017

Embed
What would you like to do?
Lambda を定期実行させる Lambda
'use strict';
const AWS = require('aws-sdk');
const funcName = <FUNCTION_NAME>;
const interval = 10000; // 10sec
function inveokeLambda(funcName) {
const lambda = new AWS.Lambda({
apiVersion: '2015-03-31'
});
const params = {
FunctionName: funcName,
InvocationType: 'Event',
};
return lambda.invoke(params).promise();
}
module.exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
inveokeLambda(funcName)
.then(() => {
let interval = setInterval(() => {
inveokeLambda(funcName);
}, interval);
return setTimeout(() => {
clearInterval(interval);
callback(null);
}, 60000);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment