AWS Lambda Update

Download AWS Lambda Update

Post on 17-Jul-2015

4.366 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

<ul><li><p>AWS Lambda Update 2015.04.22Amazon Data Service Japan,Solutions ArchitectKeisuke Nishitani(@Keisuke69)</p></li><li><p> @Keisuke69</p><p> WebEC</p></li><li><p>AWS Lambda</p><p> Compute</p><p> EC2OS</p><p> ()</p></li><li><p> AWS Lambda</p></li><li><p> Lambda</p></li><li><p>Bring your own code</p><p> Node.js</p><p> / </p><p> /tmpread/write</p></li><li><p> 100</p></li><li><p> GA AWS Mobile SDK Synchronous Invoke API </p></li><li><p>AWS Lambda now Generally Available </p><p> 100* 11000* Invoke6MB</p><p> 1:1n:n </p></li><li><p>AWS Lambda</p><p> AWS Mobile SDK AWS Mobile SDK for iOS AWS Mobile SDK for Android</p><p> Invoke RequestResponse </p></li><li><p>Lambda</p><p> Web AWS SDKAWS Mobile SDK</p><p> InvokeInvocation Type Event</p><p> RequestResponse Lambda</p></li><li><p>JavaScriptvar params = { IdentityPoolId: "Cognito Identity Pool ID, }; AWS.config.region = 'us-east-1; AWS.config.credentials = new AWS.CognitoIdentityCredentials(params); AWS.config.credentials.get(function(err) { if (!err) { var event = { 'key': 'value }; var params = { FunctionName: 'Sample, InvocationType: 'RequestResponse, LogType: 'Tail, Payload: JSON.stringify(event) }; var lambda = new AWS.Lambda(); lambda.invoke(params, function(err, data) { if (err){ console.log(err, err.stack); }else{ console.log(data.Payload); } }); } else { console.log("Error:" + err); } }); </p></li><li><p>API</p><p>DynamoDB</p><p>S3</p><p>1. HTML/JS</p><p>4. URL</p><p>JavaScriptSDK</p><p>4. URL</p><p>Lambda</p><p>3. </p></li><li><p>API</p><p>DynamoDB</p><p>S3</p><p>3. URL</p><p>2. URL</p><p>Lambda</p><p>1. </p><p>App with AWS Mobile </p><p>SDK</p></li><li><p> Amazon SNS SNS SNSAWSCloudWatchalarm</p><p>Amazon SNS Lambda function </p></li><li><p> Amazon Cognito Cognito SyncLambda</p><p>Amazon Cognito Lambda function </p></li><li><p>context</p><p> context.succeed(Object result JSON.stringifyresult</p><p> InvocationEventCloudWatch LogsLogresult</p><p> InvocaktionRequestResponseresult</p><p>Log</p><p> context.fail (Object error) error ErrornullX-Amz-Function-Error-Message</p><p>errorMessageLog</p></li><li><p>context</p><p> context.done (String message, Object result) message resultJSON.stringify messageLambda InvocationEventmessageresultCloudWatch </p><p>LogsLog InvocaktionRequestResponse</p><p> Messagenullresult MessagenullresultX-Amz-Function-Error-Message</p><p>error</p><p> messageX-Amz-Function-Error-Message</p></li><li><p>context</p><p> awsRequestId LambdaID</p><p> logStreamName CloudWatch LogsLog</p><p> clientContext SDK Null</p><p> Identity MobileSDKAmazon CognitoIdentity providor Null</p></li><li><p>console.log('Loading function'); var aws = require('aws-sdk'); var s3 = new aws.S3({apiVersion: '2006-03-01'}); exports.handler = function(event, context) { console.log('Received event:', JSON.stringify(event, null, 2)); //ContentType var bucket = event.Records[0].s3.bucket.name; var key = event.Records[0].s3.object.key; s3.getObject({Bucket: bucket, Key: key}, function(err, data) { if (err) { console.log("Error getting object " + key + " from bucket " + bucket + ". Make sure they exist and your bucket is in the same region as this function."); context.fail('Error', "Error getting file: " + err); } else { console.log('CONTENT TYPE:', data.ContentType); context.succeed(); } }); }; </p></li><li><p> Invocation Role</p><p> ExecutionInvocation2 Invocation</p><p> Lambda InvocationPull Execution Role()</p><p> Execution AWS IAMExecution Role</p></li><li><p>Execution RoleKinesis</p><p> KinesisPullLambdaKinesis</p><p> LambdaInvokeFunction</p><p>{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], "Resource": [ "*" ] }, { "Effect": "Allow", "Action": [ "kinesis:GetRecords", "kinesis:GetShardIterator", "kinesis:DescribeStream", "kinesis:ListStreams", "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "*" } ] } </p></li><li><p> AWS LambdaAccess Policy</p><p> PrincipalAWSid</p></li><li><p> S3 DynamoDB</p><p> LambdaAdd event source</p></li><li><p> CloudWatchMetrics Invocations</p><p> RequestCount </p><p> Failures ErrorCount </p><p> Duration Latency </p><p> Throttle </p></li><li><p>" WebAWS Summit" GithubKeynote" GithubAmazon" " Developers Night</p><p>http://www.awssummit.tokyo/devcon.html </p><p>623</p></li><li><p>Run Code in the cloud!</p></li></ul>