Download - AWS Lambda + AWS Cloudformation
AWS Lambda + AWS Cloudformation
Jordi MiguelMarch 2016
What is AWS Lambda?
• Compute Platform• Stateless• Event-driven• Subsecond billing
A compute service where you DON'T haveto think about:
• Servers• Deployments• Scaling and fault tolerance• OS or language updates• Metrics and logging
... 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!!!
Execution environments:
• Linux kernel version: 4.1.13
Runtime environments:
• Node.js: v0.10.36• Java: 8.0• Python: 2.7
What if I want torun other languages:
• Go: http://apex.run• Bash • C/C++ • Groovy
What is AWS Cloudformation?
• Orchestration service• Declarative• Customized via Parameters• No Extra Charge
How does it work?
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" } } } }
Can I create any resource this way??
There is a big list that coverspretty much all essentials:
• AWS::EC2• AWS::AutoScaling• AWS::ElasticLoadBalancer• AWS::RDS• ...
For everything else...
AWS::CloudFormation::CustomResource
Types of Custom Resources:
• SNS backed• Lambda backed
Basic definition: "MyCustomResource" : { "Type" : "Custom::LambdaBackedExample", "Properties" : { "ServiceToken": { "Fn::Join": [ "", [ "arn:aws:lambda:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":function:", {"Ref" : "LambdaFunctionName"} ] ] } } }
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" ], } }
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", } }
You can find this info on Amazon doc, of course...
What about the UNTOLD??
• Header Content-type for ResponseURL• Content of "Data" object• Lambda unresponsive• Lambda serializer
DEMO TIME!!