lambda-slack-bot

command module
v0.0.0-...-fd648a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

lambda-slack-bot

A Golang AWS Lambda to list running EC2 instanes - used by a Slack bot, to better control AWS spendings. For further details reads this post.

Compile

GOOS=linux go build -o main

Deployment

export AWS_STACK_NAME=lalyos-lambda-go
export AWS_S3_BUCKET=lp-lambda-go

aws cloudformation package --template-file template.yml --s3-bucket $AWS_S3_BUCKET --output-template-file packaged.yml
aws cloudformation deploy --template-file ./packaged.yml --stack-name $AWS_STACK_NAME --capabilities CAPABILITY_IAM

Invoke API

AWS_API_ID=$(aws apigateway get-rest-apis --query 'items[? name == `'$AWS_STACK_NAME'`].id' --out text)
AWS_STAGE=$(aws apigateway get-stages --rest-api-id $AWS_API_ID --query 'item[0].stageName' --out text)

curl https://$AWS_API_ID.execute-api.$AWS_DEFAULT_REGION.amazonaws.com/$AWS_STAGE/ -d geza

List stacks

aws cloudformation list-stacks \
  --stack-status-filter CREATE_COMPLETE  \
  --query StackSummaries[].StackName \
  --out table

list lambda fn in stack

aws cloudformation list-stack-resources \
  --stack-name $AWS_STACK_NAME \
  --query 'StackResourceSummaries[?ResourceType == `AWS::Lambda::Function`].PhysicalResourceId' \
  --out text

list all resorces:

aws cloudformation list-stack-resources \
  --stack-name $AWS_STACK_NAME \
  --query 'StackResourceSummaries[].[ResourceType,PhysicalResourceId,LogicalResourceId]' \
  --out table

list regions:

aws ec2 describe-regions \
  --query 'join(`,`, Regions[].RegionName | sort(@))' \
  --out text

exclude one:

aws ec2 describe-regions \
  --query 'join(`,`, Regions[? RegionName != `ap-northeast-2`].RegionName | sort(@))' \
  --out text

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL