Transcript
Page 1: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

November 14, 2014 | Las Vegas, NV

Tim Hunt, Sr. Product Manager, Amazon S3

Page 2: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 3: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 4: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

S3

Events

SNS topic

SQS queue

Lambda function

Notifications

Foo() {…}

-- Preview --

Page 5: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

Integration – A new surface on the

Amazon S3 “building block” for event-

based computing

Speed – typical time to send

notifications is less than a second

Simplicity – Avoids proxies or polling

to detect changesProxy

List/Diff

Notifications

or

Page 6: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 7: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

S3 Lambda

Foo() {…}

Notification

Page 8: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 9: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 10: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 11: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 12: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 13: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 14: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 15: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 16: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// read values from the event

// sanity check: validate that source and destination are different buckets

// make sure it‘s a jpg or png

Page 17: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// read values from the event

var srcBucket = event.Records[0].s3.bucket.name;

var srcKey = event.Records[0].s3.object.key;

var dstBucket = srcBucket + "resized";

var dstKey = "resized-" + srcKey;

// sanity check: validate that source and destination are different buckets

// make sure it‘s a jpg or png

Page 18: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// read values from the event

// sanity check: validate that source and destination are different buckets

if (srcBucket == dstBucket) {

return;

}

// make sure it‘s a jpg or png

Page 19: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// read values from the event

// sanity check: validate that source and destination are different buckets

// make sure it‘s a jpg or png

var imageType = srcKey.match(/\.([^.]*)$/)[1];

if (imageType != "jpg" && imageType != "png") {

return;

}

Page 20: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// download image from S3 into buffer

// generate the thumbnail

// Put into S3

function upload(data, next) {

s3.putObject({Bucket: dstBucket, Key: dstKey, Body: data, ContentType: contentType}, next);

Page 21: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// download image from S3 into buffer

function download(next) {

s3.getObject({Bucket: srcBucket, Key: srcKey}, next);

},

// generate the thumbnail

// Put into S3

function upload(data, next) {

s3.putObject({Bucket: dstBucket, Key: dstKey, Body: data, ContentType: contentType}, next);

Page 22: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// download image from S3 into buffer

// generate the thumbnail

function tranform(response, next) {

gm(response.Body).size(function(err, size) {

this.resize(width, height).toBuffer(imageType, function(err, buffer) {

if (err) { next(err);}

else {next(null, response.ContentType, buffer);}

});

});

},

// Put into S3

function upload(data, next) {

s3.putObject({Bucket: dstBucket, Key: dstKey, Body: data, ContentType: contentType}, next);

Page 23: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// download image from S3 into buffer

// generate the thumbnail

// Put into S3

function upload(data, next) {

s3.putObject({Bucket: dstBucket, Key: dstKey, Body: data, ContentType: contentType}, next);

Page 24: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 25: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 26: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 27: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

Continued…

Page 28: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 29: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

SQSS3 EC2

Foo() {…}

DynamoDB

Notification

Web Page

Page 30: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

while (true) {

// Long poll for the messages

List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

for (Message message : messages) {

// Process the message

processMessage(message.getBody());

// Delete the message after we are done.

sqs.deleteMessage(myQueueUrl, message.getReceiptHandle());

}

}

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 31: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

while (true) {

// Long poll for the messages

List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

for (Message message : messages) {

// Process the message

processMessage(message.getBody());

// Delete the message after we are done.

sqs.deleteMessage(myQueueUrl, message.getReceiptHandle());

}

}

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 32: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

while (true) {

// Long poll for the messages

List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

for (Message message : messages) {

// Process the message

processMessage(message.getBody());

// Delete the message after we are done.

sqs.deleteMessage(myQueueUrl, message.getReceiptHandle());

}

}

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 33: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

while (true) {

// Long poll for the messages

List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

for (Message message : messages) {

// Process the message

processMessage(message.getBody());

// Delete the message after we are done.

sqs.deleteMessage(myQueueUrl, message.getReceiptHandle());

}

}

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 34: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Parse the bucket and key from the event notification

// Skip thumbnails to avoid recursion

// Download the file from S3

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 35: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Parse the bucket and key from the event notification

S3EventNotificationRecord item = S3EventNotificationItem.parseJson(messageBody).getRecords().get(0);

String bucketName = item.getS3().getBucket().getName();

String objectName = item.getS3().getObject().getObjectNameOnly();

String thumbnailFileName = thumbnailPrefix + objectName;

// Skip thumbnails to avoid recursion

// Download the file from S3

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 36: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Parse the bucket and key from the event notification

if (objectName.startsWith(thumbnailPrefix)) {

return; // Skip thumbnails to avoid recursion

}

// Download the file from S3

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 37: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Parse the bucket and key from the event notification

// Skip thumbnails to avoid recursion

// Download the file from S3

s3.getObject(new GetObjectRequest(bucketName, objectName), new File(tempFileName));

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 38: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Read the GPS info from the file

// Put the photo info into DynamoDB for public website display

// Generate a thumbnail and put it into S3

// Notify our web page to add it to the map

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 39: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Read the GPS info from the file

double[] gps = readGpsFromEXIF(tempFileName);

// Put the photo info into DynamoDB for public website display

// Generate a thumbnail and put it into S3

// Notify our web page to add it to the map

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 40: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Read the GPS info from the file

// Put the photo info into DynamoDB for public website display

putNewPhotoInDynamo (bucketName, objectName, gps, "http://" +sourceBucketName + ".s3.amazonaws.com/" + thumbnailFileName);

// Generate a thumbnail and put it into S3

// Notify our web page to add it to the map

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 41: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Read the GPS info from the file

// Put the photo info into DynamoDB for public website display

// Generate a thumbnail and put it into S3

generateThumbnail(tempFileName, thumbnailFileName);

s3.putObject(sourceBucketName, thumbnailFileName, new File(thumbnailFileName));

// Notify our web page to add it to the map

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 42: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

// Read the GPS info from the file

// Put the photo info into DynamoDB for public website display

// Generate a thumbnail and put it into S3

// Notify our web page to add it to the map

sqs.sendMessage(sqs.createQueue(realTimeQueueName).getQueueUrl(), key);

Authentication and access control not shown for brevity, but published best practices should be followed.

Page 43: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 44: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 45: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 46: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 47: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 48: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 49: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 50: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 51: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 52: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 53: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 54: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 55: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 56: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 57: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 58: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 59: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 60: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 61: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 62: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 63: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 64: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 65: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 66: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 67: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 68: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 69: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 70: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

http://bit.ly/awsevals

Page 71: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 72: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 73: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 74: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 75: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 76: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 77: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 78: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 79: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 80: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 81: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 82: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 83: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 84: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 85: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 86: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 87: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

Amazon

Page 88: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 89: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 90: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 91: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 92: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 93: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 94: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 95: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 96: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 97: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014
Page 98: (SDD413) Amazon S3 Deep Dive and Best Practices | AWS re:Invent 2014

Top Related