Serverless Framework template to schedule start / stop EC2 on Lambda

This is the 16th day article of AWS Lambda Advent Calendar 2017.

Serverless Framework

Introduction

Setting up the environment

Deploy with Serverless Framework

Get source

$ git clone https://github.com/ukitiyan/operation-ec2-instance.git

Import to STS (Eclipse)

Modify serverless.yml + Build

serverless.yml


- schedule:
    rate: cron(30 11 * * ? *)
    input:
      goal: stop
      instanceId: i-XXXXXXXXXXXXXXXXX
- schedule:
    rate: cron(0 23 * * ? *)
    input:
      goal: start
      instanceId: i-XXXXXXXXXXXXXXXXX

Deploy

$ cd operation-ec2-instance
$ serverless deploy -v
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
・
・
Serverless: Stack update finished...
Service Information
service: operation-ec2-instance
stage: prod
region: ap-northeast-1
api keys:
  None
endpoints:
  None
functions:
  aws-java-maven-prod-hello: arn:XXXXXXXX
{
  "goal": "stop",
  "instanceId": "i-XXXXXXXXXXXXXXXXX"
}

Summary

Recommended Posts

Serverless Framework template to schedule start / stop EC2 on Lambda
How to deploy Java to AWS Lambda with Serverless Framework
I tried deploying a Docker container on Lambda with Serverless Framework
Note: [Docker] How to start and stop
You can do it right away with Serverless Framework Serverless on AWS (API + Lambda [java] is easy to set up)