Using Lambda as a CloudTrail Event Handler

Elliott Spira

מי אנחנו

About These AWS Products

Lambda

  • Run code in response to events
  • Serverless execution model
  • Store code in S3
  • Now supports scheduled executions

CloudTrail

  • Record of AWS API calls
  • Records contain:
    • The API call (method and parameters)
    • The caller (IP and ARN)
    • The call source (CLI, SDK, CloudFormation, console)

Case Study: Auto Tag

Auto Tag

  • Automatically tag resources in AWS as they are created
  • Presented at AWS re:Invent break out session

Single Account

Multi-Account

Implementation

  • nodejs in ecmascript2015 (es6/harmony)
  • used babel to transpile to es5
  • deploying to lambda is super simple

Deployment

#!/bin/bash

echo 1. Zipping code for deployment

pushd lib
zip -r autotag.zip *
popd
mv lib/autotag.zip .
zip -g autotag.zip -r node_modules/

echo ---

echo 2. Uploading code via AWS CLI

aws lambda --region ap-northeast-1 update-function-code \
--function-name arn:aws:lambda:ap-northeast-1:[account_id]:function:gs_autotag \
--zip-file fileb:///home/e/dev/gs/autotag/autotag.zip

Let's
Write
Code

fork on github

github.com/GorillaStack/auto-tag

thanks!

@GorillaStack

gorillastack

@ElliottSpira

em0ney

gorillastack.com

Using Lambda as a Cloudtrail Event Handler

By em0ney

Using Lambda as a Cloudtrail Event Handler

This presentation explores how to use lambda as an event handler for CloudTrail.

  • 948