layout: true class: middle --- class: center # AWS Lambda Overview Ryan Scott Brown — [@ryan_sb](https://twitter.com/ryan_sb) --- # Agenda 1. Platforms & Positioning 1. Event Sources 1. S3 Handlers 1. Of Web Apps & Workers 1. Restrictions .footnote[Stop me any time for questions] --- class: center # Think PaaS
EC2 == Infrastructure
Beanstalk == Platform
Lambda == Platform...er? --- class: center, middle # No server is simpler than no server at all --- # Use Cases * API backends (mobile, web, IoT) * Microservices with API Gateway * On-demand workers * Data pipelines with S3, DynamoDB, and Kinesis * Build smarter infrastructure Critically, you never pay for idle time --- # How it Works Events come in, code executes on the event ``` { "Records": [ { "eventVersion": "2.0", "eventTime": "1970-01-01T00:00:00.000Z", "s3": { "configurationId": "testConfigRule", "object": { "eTag": "0123456789abcdef0123456789abcdef", "sequencer": "0A1B2C3D4E5F678901", "key": "HappyFace.jpg", "size": 1024 }, "bucket": {"arn": "arn:aws:s3:::mybucket", "name": "sourcebucket"}, "s3SchemaVersion": "1.0" }, "awsRegion": "us-east-1", "eventName": "ObjectCreated:Put", "eventSource": "aws:s3" } ] } ``` --- # S3 * Decide what actions you want triggers on * Yes, you can make infinite loops (yay?) * Events can be for all keys, one folder, or a specific suffix (`*.png`) --- # Quick Example Make your bucket all public, all the time ``` import boto3 s3 = boto3.client('s3') def lambda_handler(event, context): for rec in event['Records']: client.put_object_acl( Bucket=rec['s3']['bucket']['name'], Key=rec['s3']['object']['key'], ACL='public-read', ) ``` --- # Kinesis Lambda (the service) invokes your Lambda (custom code) with events * Durable event streams from *any* application * Many consumers * Kinesis ensures that all jobs are seen by consumers --- # DynamoDB Think triggers or stored procedures * Complex data validations * Replication or record keeping * Update other copies of the data * Receive both the new and old values for comparison --- # SNS * Got CloudWatch? * External services have SNS integration already * Coordinate pipelines with SNS --- # API Gateway * REST API in front of Lambda * Handles API keys and rate limiting * Flexible request routing * Custom error code handling --- # Greenfield Applications --- # Brownfield Development * Worker system * Backend-For-Frontend * New feature * Scheduled tasks --- # Restrictions * Node.js v0.10, Python 2.7, or Java 8 * 6MB request size * 10 second HTTP API timeout * 300 seconds execution limit * 50 MB deployment package --- # Deploying Plenty of 3rd-party tools, but the artifacts are zip files in S3, making any deploy pipeline viable --- # Versioned Functions `arn:aws:lambda:aws-region:acct-id:function:myFunction` `arn:aws:lambda:aws-region:acct-id:function:myFunction:$LATEST` `arn:aws:lambda:aws-region:acct-id:function:myFunction:v0.1.1` `arn:aws:lambda:aws-region:acct-id:function:myFunction:PROD` --- class: middle # Questions? .small[I also run [serverlesscode.com](https://serverlesscode.com) if you want more Lambda tips, projects, and news.] .footnote[These slides are available at [rsb.io/talks/aws-lambda](https://rsb.io/talks/aws-lambda/)]