Introduction To Amazon s3
Introduction To Amazon s3
Amazon S3
Ashay Shirwadkar
Agenda
What is Amazon S3?
Storage Classes
Namespace
Security
Server Side encryption
Access Control
S3 APIs
But before that...
What?
- Cloud computing, also on-demand computing, is a kind of
Internet-based computing that provides shared processing
resources.
- Resources being
- Networks
- Servers
- Storage
- Applications and services
Why?
- The term cloud is used as a metaphor for the Internet.
- So it means nothing. Just a nice word and now it's hot....
Types of storage
Client Server
Object
NFS/SMB/rsync
REST APIs
iSCSI/AoE/Fiber Channel
What is amazon S3?
Amazon S3 is acronym stands for Simple Storage Service .
S3 is web store, not a file system, it’s simple write once, read many (WORM) object
store having eventual consistency.
“Write once” means that an object cannot be changed after it is written, and “read many” means that
multiple copies of the object are made across different availability zones.
S3 is secure, durable & highly-scalable. It is accessed Via API’s (SOAP and REST)
Server side encryption
Data is stored with 99.999999999% durability
Stores data ranging from 1B to 5TB
Globally Unique
bucket name + object name (key) => Uniquely identify each object in a S3 cloud. Every object can be
addressed through bucket and key combination.
Encrypted Object
Object Encrypted
Bucket
Data
Encrypted
per-object key
per-object
key
Key Management
(monthly rotated)
Master Key
Access Control
S3 provides Policies, ACL’s and IAM (Identity and Access Management)
Use these to define rules for sharing objects or buckets
Allow Allow
Allow
Bob, John
Bob, John
Actions:
PutObject Actions:
Actions:
PutObject
Read
Resource:
arn:aws:s3:::mybucket/* Resource:
arn:aws:s3:::mybucket/*
String to sign
- Every request has different string to sign.
S3 Authentication - Client side
● Create Request String to Sign Format
String to Sign StringToSign = HTTP-Verb + "\n" +
Request GET\n Content-MD5 + "\n" +
GET /foo/bar.jpg HTTP/1.1 \n Content-Type + "\n" +
Host: johnsmith.s3.amazonaws.com \n Date + "\n" +
Date: Mon, 26 Mar 2007 19:37:58 +0000 Mon, 26 Mar 2007 19:37:58 +0000\n Canonicalized Amz
/johnsmith/foo/bar.jpg Headers +
CanonicalizedResource;
String to Sign
...
HMAC
● Create HMAC-SHA1 calculation
Your
Signature
Signature and
Base64
Encoding
Secret Access
Key
Request
GET /foo/bar.jpg HTTP/1.1
Host: johnsmith.s3.amazonaws.com
● Send Request Date: Mon, 26 Mar 2007 19:37:58 +0000
String to Sign
...
HMAC Calculated
● Create HMAC-SHA1 calculation Signature
Signature and
Base64
Encoding
Secret Access
Key
Calculated Your
Signature Signature
● Compare Two Yes: Request is authenticated
Signatures No: Request authentication fails
Operations on Buckets
Standard Operations
Put Bucket - Creates bucket if does not exist.
Get Bucket - List all the objects within the bucket.
Delete Bucket - Deletes the bucket. All the objects within the buckets must be deleted.
Other operations
Bucket lifecycle configuration - Set the lifecycle of objects within the bucket
Bucket policies - Set policies on bucket
Bucket location - Set the location of bucket
Bucket notification - Receive notifications when certain events happen in your bucket
Bucket logging - Enable logging for a bucket
Bucket request Payment - Returns the request payment configuration of a bucket.
Bucket versioning - Enable versioning of objects within the bucket
Operations on Objects
Standard Operations
Put Object - Creates Object.
Post Object- POST is an alternate form of PUT that enables browser-based uploads.
Get Object - Gets object along with its metadata.
Head object - Gets only metadata.
Delete Object - Deletes the Object.
Multipart Upload
Upload a single object as a set of parts.
Each part is a contiguous portion of the object's data.
Upload for objects from 5 MB to 5 TB in size.
Other operations
Object ACL’s - set the ACL permissions for an object that already exists in a bucket.
Object Copy - Creates a copy of an object
Multipart Upload
Initiate Multipart Upload
Initiates a multipart upload and returns an upload ID.
Provide this upload ID in each subsequent upload part requests.
Responce
Request
HTTP/1.1 200 OK
POST /example-object?uploads HTTP/1.1
x-amz-id-2: Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==
Host: example-bucket.s3.amazonaws.com
x-amz-request-id: 656c76696e6727732072657175657374
Date: Mon, 1 Nov 2010 20:34:56 GMT
Date: Mon, 1 Nov 2010 20:34:56 GMT
Authorization: authorization string
Content-Length: 197
Connection: keep-alive
Server: AmazonS3
Request Responce
PUT /example-object?partNumber=1&
HTTP/1.1 200 OK
uploadId=VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5tMnRzIHVwbG9h
x-amz-id-2:
ZA
Vvag1LuByRx9e6j5Onimru9pO4ZVKnJ2QRPfTaOFg==
HTTP/1.1
x-amz-request-id: 656c76696e6727732072657175657374
Host: example-bucket.s3.amazonaws.com
Date: Mon, 1 Nov 2010 20:34:56 GMT
Date: Mon, 1 Nov 2010 20:34:56 GMT
ETag: "b54357faf0632cce46e942fa68356b38"
Content-Length: 10485760
Content-Length: 0
Content-MD5: pUNXr/BjKK5G2UKvaRRrOA==
Connection: keep-alive
Authorization: authorization string
Server: AmazonS3
***part data omitted***
Multipart Upload
Complete Multipart Upload
Completes a multipart upload by assembling previously uploaded parts.
Request Responce
POST /example-object? HTTP/1.1 200 OK
uploadId=VXBsb2FkIElEIGZvciA2aWWpbmcncyBteS1tb3ZpZS5t x-amz-id-2:
MnRzIHVwbG9hZA HTTP/1.1 Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==
Host: example-bucket.s3.amazonaws.com x-amz-request-id: 656c76696e6727732072657175657374
Date: Mon, 1 Nov 2010 20:34:56 GMT Date: Mon, 1 Nov 2010 20:34:56 GMT
Content-Length: 391 Connection: close
Authorization: authorization string Server: AmazonS3
Get Object
Request
GET /example-object HTTP/1.1
Host: example-bucket.s3.amazonaws.com
Date: Mon, 1 Nov 2010 20:34:56 GMT
Authorization: authorization string
API Operations-
API Operations contd.
DEMO
Create Bucket
#!/bin/bash -x
bucket=$1
Request < HTTP/1.1 200 OK
< x-amz-id-2: Responce
if [ -z "$1" ] jWt9BVmZkL1eU/i1gRoUrsB19/RHYwHGJZdst5ttGlLx7IvFPzHDSSNFluRyDRrCewG4xoFi
oJA=
then
< x-amz-request-id: 9FC84EB054B018F9
echo "usage: ./bucket_put <bucket_name>" < Date: Wed, 12 Aug 2015 11:52:02 GMT
exit 1 < Location: /casoft
fi < Content-Length: 0
resource="/${bucket}/" * Server AmazonS3 is not blacklisted
dateValue=`date -R` < Server: AmazonS3
stringToSign="PUT\n\n\n${dateValue}\n${resource}" <
s3Key=’Your Access Key’ * Connection #0 to host calsoft.s3.amazonaws.com left intact
s3Secret=’Your Secret Access Key’
signature=`echo -en ${stringToSign} | openssl sha1 -hmac $
{s3Secret} -binary | base64`
curl -v -X PUT \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
http://${bucket}.s3.amazonaws.com/
List Bucket
#!/bin/bash -x Request < HTTP/1.1 200 OK Responce
bucket=$1 < x-amz-id-2:
if [ -z "$1" ] nBbw0yclRZ4jPzPEECEKI0oCRMQrdIihEXbCVuUvYdXl75CGYH3/IcsPu/jxkCJb
< x-amz-request-id: 90A0E3312B09453A
then
< Date: Wed, 12 Aug 2015 11:55:48 GMT
echo "usage: ./bucket_list <bucket_name>" < x-amz-bucket-region: us-east-1
exit 1 < Content-Type: application/xml
fi < Transfer-Encoding: chunked
resource="/${bucket}/" * Server AmazonS3 is not blacklisted
dateValue=`date -R` < Server: AmazonS3
s3Key=’Your Access Key’ <
s3Secret=’Your Secret Access Key’ <?xml version="1.0" encoding="UTF-8"?>
* Connection #0 to host calsoft.s3.amazonaws.com left intact
signature=`echo -en ${stringToSign} | openssl sha1 -hmac $
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-
{s3Secret} -binary | base64` 01/"><Name>calsoft</Name><Prefix></Prefix><Marker></
curl -v -X GET \ Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated></
-H "Host: ${bucket}.s3.amazonaws.com" \ ListBucketResult>
-H "Date: ${dateValue}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
http://${bucket}.s3.amazonaws.com/
Delete Bucket
#!/bin/bash -x
bucket=$1
Request < HTTP/1.1 204 No Content
< x-amz-id-2: Responce
if [ -z "$1" ] 4uuTflJqeUnewAYGmgghfiaBf/yfdja3DE7GmC9+e0QmBmE9T+2c/Ylt19jcndrM
< x-amz-request-id: 96AEC8E1A534EC3E
then
< Date: Wed, 12 Aug 2015 12:06:44 GMT
echo "usage: ./bucket_delete <bucket_name>" * Server AmazonS3 is not blacklisted
exit 1 < Server: AmazonS3
fi <
resource="/${bucket}/" * Connection #0 to host calsoft.s3.amazonaws.com left intact
dateValue=`date -R`
s3Key=’Your Access Key’
s3Secret=’Your Secret Access Key’
signature=`echo -en ${stringToSign} | openssl sha1 -hmac $
{s3Secret} -binary | base64`
curl -v -X DELETE \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/
Create Object
#!/bin/bash -x
bucket=$1 Request < HTTP/1.1 100 Continue
Responce
* We are completely uploaded and fine
file=$2 < HTTP/1.1 200 OK
if [[ (-z "$1") || (-z "$2") ]]
then
< x-amz-id-2:
echo "usage: ./object_upload <bucket_name> <object_name>" OzR2U7CgsWwtHVbF8qcTiIpezFk5FVt9PxoFq9Px2QP8y7L0kOR2gQysfu9/EFNjUBdqIrzs
exit 1 E2o=
fi < x-amz-request-id: 301904328CA5B6FF
resource="/${bucket}/${file}" < Date: Wed, 12 Aug 2015 12:08:01 GMT
contentType="application/text" < ETag: "78d5333e735ae15f5f19f2e76838b728"
dateValue=`date -R` < Content-Length: 0
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=’Your Access Key’
* Server AmazonS3 is not blacklisted
s3Secret=’Your Secret Access Key’ < Server: AmazonS3
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | <
base64` * Connection #0 to host calsoft.s3.amazonaws.com left intact
curl -v -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
List Object
#!/bin/bash -x
bucket=$1 Request < HTTP/1.1 200 OK
< x-amz-id-2: Responce
file=$2 7yX1htWSKHVn+ssy32emeQoaF8WgFjRQuEio4PNzSyxjoJiPnmjcsmJvbJFZTTDx
if [[ (-z "$1") || (-z "$2") ]] < x-amz-request-id: 1786B98B373C737E
then < Date: Wed, 12 Aug 2015 12:11:42 GMT
echo "usage: ./object_download <bucket_name> < Last-Modified: Wed, 12 Aug 2015 12:08:01 GMT
<object_name>" < ETag: "78d5333e735ae15f5f19f2e76838b728"
exit 1 < Accept-Ranges: bytes
fi < Content-Type: application/text
resource="/${bucket}/${file}" < Content-Length: 12
dateValue=`date -R` * Server AmazonS3 is not blacklisted
stringToSign="GET\n\n\n${dateValue}\n${resource}" < Server: AmazonS3
s3Key=’Your Access Key’ <
s3Secret=’Your Secret Access Key’ Hello,World
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} - * Connection #0 to host calsoft.s3.amazonaws.com left intact
binary | base64`
curl -v -X GET \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
Delete Object
#!/bin/bash -x
bucket=$1 Request < HTTP/1.1 204 No Content
< x-amz-id-2: Responce
file=$2 swMz88s6IV8i3dCwP6fSuklrubABX0O7XV1jBt7fUZtCP2x86IPozq+5Usy5wE7x
if [[ (-z "$1") || (-z "$2") ]] < x-amz-request-id: 247E152DAB64A000
then < Date: Wed, 12 Aug 2015 12:14:58 GMT
echo "usage: ./object_delete <bucket_name> * Server AmazonS3 is not blacklisted
<object_name>" < Server: AmazonS3
exit 1 <
fi * Connection #0 to host calsoft.s3.amazonaws.com left intact
resource="/${bucket}/${file}"
dateValue=`date -R`
stringToSign="DELETE\n\n\n${dateValue}\n${resource}"
s3Key=’Your Access Key’
s3Secret=’Your Secret Access Key’
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -
binary | base64`
curl -v -X DELETE \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
Q&A