Lambda - 함수 - 함수생성
권한 - ec2권한
Node
- Start
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.instanceRegion});
ec2.startInstances({ InstanceIds: event.instanceId}).promise()
.then(() => callback(null, `Successfully started ${event.instanceId}`))
.catch(err => callback(err));
};
- Stop
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.instanceRegion});
ec2.stopInstances({ InstanceIds: event.instanceId}).promise()
.then(() => callback(null, `Successfully stopped ${event.instanceId}`))
.catch(err => callback(err));
};
요청
{
"instanceId": [
"test instance id"
],
"instanceRegion": "ap-northeast-2"
}
Cloud watch
이벤트 - 규칙 - 규칙생성 - 일정 - cron표현식