GitXplorerGitXplorer
K

go-serverless-ec2-lifespan

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
92f792b081d56e31f662f6b6d2f0ac30fdade9f5

update readme

KKav91 committed 7 years ago
Unverified
9c6694d2debbe4f2f74d4e86b84f0bcd3dcfadd0

update readme

KKav91 committed 7 years ago
Unverified
1b88b2f12139d4c1ce11865ed6ac0dcc547a45b2

init

KKav91 committed 7 years ago

README

The README file for this repository.

Serverless Golang - EC2 Lifespan Lambda

Provide an EC2 Instance a Lifespan tag with integer value representing remaining minutes left to live or time eg. 14:22 to stop by.

  • example
    • "10" (10 minutes left to live)
    • "15:30" (will stop at specificed time)
  • Optionally supply -terminate at the end of time period, to terminate the instance
    • "10-terminate" (will terminate instance in 10m)
    • "12:44-terminate" (will terminate instance at 12:44)
Ensure you have serverless framework installed & relevant imports added, see within .go files
https://serverless.com/framework/docs/providers/aws/guide/installation/

aws sdk see: https://docs.aws.amazon.com/sdk-for-go/api/
Other packages:
go get -u github.com/sirupsen/logrus
go get -u github.com/korovkin/limiter
go get -u github.com/aws/aws-lambda-go/lambda

Config

serverless.yml file
See region, memorySize & timeout options to adjust if required.

main.go file
There are several options to adjust as below:

//If AWS_REGION environment variable is supplied the below default will be overwritten
var region = "us-east-1" 

//Lambda timezone is UTC by default, this will correct it if using the timestamp option
var timezone = "Australia/Sydney" 

//If an invalid lifespan tag is supplied it will be given 86400 minutes to like == 1 day
var defaultLifespan = 86400 

//limit number of concurrent executions, useful if you are making a large amount of calls to the EC2 API service
var concurrency = 5 

Compiling & Deploying

As AWS Lambda runs on linux you will need to compile for linux. For further info: https://github.com/aws/aws-lambda-go

GOOS=linux GOARCH=amd64 go build -o bin/main main.go ec2.go
sls deploy -v