20
AWS Lambda + AWS Cloudformation Jordi Miguel March 2016

AWS Lambda + AWS Cloudformation

Embed Size (px)

Citation preview

Page 1: AWS Lambda + AWS Cloudformation

AWS Lambda + AWS Cloudformation

Jordi MiguelMarch 2016

Page 2: AWS Lambda + AWS Cloudformation

What is AWS Lambda?

• Compute Platform• Stateless• Event-driven• Subsecond billing

Page 3: AWS Lambda + AWS Cloudformation

A compute service where you DON'T haveto think about:

• Servers• Deployments• Scaling and fault tolerance• OS or language updates• Metrics and logging

Page 4: AWS Lambda + AWS Cloudformation

... but where you can easily:

• Bring your own code...even native libraries• Run code in parallel• Create backends, event handlers,and data processing systems• Never pay for idle!!!

Page 5: AWS Lambda + AWS Cloudformation

Execution environments:

• Linux kernel version: 4.1.13

Runtime environments:

• Node.js: v0.10.36• Java: 8.0• Python: 2.7

Page 6: AWS Lambda + AWS Cloudformation

What if I want torun other languages:

• Go: http://apex.run• Bash • C/C++ • Groovy

Page 7: AWS Lambda + AWS Cloudformation

What is AWS Cloudformation?

• Orchestration service• Declarative• Customized via Parameters• No Extra Charge

Page 8: AWS Lambda + AWS Cloudformation

How does it work?

Page 9: AWS Lambda + AWS Cloudformation

Get a closer look to the template file:

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "A simple Amazon EC2 instance", "Resources" : { "MyEC2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : "ami-2f726546", "InstanceType" : "t1.micro" } } } }

Page 10: AWS Lambda + AWS Cloudformation

Can I create any resource this way??

Page 11: AWS Lambda + AWS Cloudformation

There is a big list that coverspretty much all essentials:

• AWS::EC2• AWS::AutoScaling• AWS::ElasticLoadBalancer• AWS::RDS• ...

Page 12: AWS Lambda + AWS Cloudformation

For everything else...

AWS::CloudFormation::CustomResource

Page 13: AWS Lambda + AWS Cloudformation

Types of Custom Resources:

• SNS backed• Lambda backed

Page 14: AWS Lambda + AWS Cloudformation

Basic definition: "MyCustomResource" : { "Type" : "Custom::LambdaBackedExample", "Properties" : { "ServiceToken": { "Fn::Join": [ "", [ "arn:aws:lambda:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":function:", {"Ref" : "LambdaFunctionName"} ] ] } } }

Page 15: AWS Lambda + AWS Cloudformation

Lambda input event: { "RequestType" : "Create", "ResponseURL" : "http://pre-signed-S3-url-for-response", "StackId" : "arn:aws:cloudformation:us-west-2:123456789012:stack/stack-name/guid", "RequestId" : "unique id for this create request", "ResourceType" : "Custom::LambdaBackedExample", "LogicalResourceId" : "MyCustomResource", "ResourceProperties" : { "foo" : "urls", "bar" : [ "http://mysite.com", "http://myecommercesite.com/", "http://search.mysite.com" ], } }

Page 16: AWS Lambda + AWS Cloudformation

Cloudformation response: { "Status" : "SUCCESS", "PhysicalResourceId" : "Tester1", "StackId" : "arn:aws:cloudformation:us-west-2:123456789012:stack/stack-name/guid", "RequestId" : "unique id for this create request", "LogicalResourceId" : "MySeleniumTester", "Data" : { "resultsPage" : "http://www.myexampledomain/test-results/guid", "lastUpdate" : "2012-11-14T03:30Z", } }

Page 17: AWS Lambda + AWS Cloudformation

You can find this info on Amazon doc, of course...

Page 18: AWS Lambda + AWS Cloudformation

What about the UNTOLD??

• Header Content-type for ResponseURL• Content of "Data" object• Lambda unresponsive• Lambda serializer

Page 19: AWS Lambda + AWS Cloudformation

DEMO TIME!!

Page 20: AWS Lambda + AWS Cloudformation