Upload
keisuke-nishitani
View
4.386
Download
1
Embed Size (px)
Citation preview
AWS Lambda Update 2015.04.22Amazon Data Service Japan,Solutions ArchitectKeisuke Nishitani(@Keisuke69)
@Keisuke69
WebEC
AWS Lambda
Compute
EC2OS
()
AWS Lambda
Lambda
Bring your own code
Node.js
/
/tmpread/write
100
GA AWS Mobile SDK Synchronous Invoke API
AWS Lambda now Generally Available
100* 11000* Invoke6MB
1:1n:n
AWS Lambda
AWS Mobile SDK AWS Mobile SDK for iOS AWS Mobile SDK for Android
Invoke RequestResponse
Lambda
Web AWS SDKAWS Mobile SDK
InvokeInvocation Type Event
RequestResponse Lambda
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); } });
API
DynamoDB
S3
1. HTML/JS
4. URL
JavaScriptSDK
4. URL
Lambda
3.
API
DynamoDB
S3
3. URL
2. URL
Lambda
1.
App with AWS Mobile
SDK
Amazon SNS SNS SNSAWSCloudWatchalarm
Amazon SNS Lambda function
Amazon Cognito Cognito SyncLambda
Amazon Cognito Lambda function
context
context.succeed(Object result JSON.stringifyresult
InvocationEventCloudWatch LogsLogresult
InvocaktionRequestResponseresult
Log
context.fail (Object error) error ErrornullX-Amz-Function-Error-Message
errorMessageLog
context
context.done (String message, Object result) message resultJSON.stringify messageLambda InvocationEventmessageresultCloudWatch
LogsLog InvocaktionRequestResponse
Messagenullresult MessagenullresultX-Amz-Function-Error-Message
error
messageX-Amz-Function-Error-Message
context
awsRequestId LambdaID
logStreamName CloudWatch LogsLog
clientContext SDK Null
Identity MobileSDKAmazon CognitoIdentity providor Null
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(); } }); };
Invocation Role
ExecutionInvocation2 Invocation
Lambda InvocationPull Execution Role()
Execution AWS IAMExecution Role
Execution RoleKinesis
KinesisPullLambdaKinesis
LambdaInvokeFunction
{ "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": "*" } ] }
AWS LambdaAccess Policy
PrincipalAWSid
S3 DynamoDB
LambdaAdd event source
CloudWatchMetrics Invocations
RequestCount
Failures ErrorCount
Duration Latency
Throttle
" WebAWS Summit" GithubKeynote" GithubAmazon" " Developers Night
http://www.awssummit.tokyo/devcon.html
623
Run Code in the cloud!