Amazon S3 Storage

3 new courses on s3
https://aws.amazon.com/it/about-aws/whats-new/2021/01/announcing-three-new-digital-courses-for-amazon-s3/

Pagina di riferimento http://aws.amazon.com/documentation/s3/

Get-S3PreSignedURL -BucketName ($S3BucketName) -Key ($s3FileName) -Region $S3Region -Expire $expire

Use KMS to store the data encrypted

aws s3 cp --region eu-west-1 --sse aws:kms --sse-kms-key-id arn:aws:kms:eu-west-1:11111111111:key/aaaaaaa-bbbb-cccc-dddd file.txt s3:/mys3bucket/

to use Kms you need to give the permissions on the key , if you want to do a cross account backup with encryption you need to remember these two rules

  1. after that you modify a policy don't forget to wait 20/30 seconds before test the new change.
  2. if you try to access to a key in the account 1111111 from a role in the account 222222 , you need to give the permissions on the key on the account 111111 and the same permissions in the role defined in the account 222222 .

the first check for the permission is the describe key command line

aws kms describe-key --key-id arn:aws:kms:eu-west-1:11111111111:key/aaaaaaa-bbbb-cccc-dddd --region eu-west-1

Costi

Pagina di riferimento dei costi http://aws.amazon.com/s3/pricing/
I prezzi e le modalità sembrano quelle abituali. Dice che non si paga per trasferimenti in una regione amazon via richiesta di copia. Tra regioni invece si paga regolarmente. Non si paga tra ec2 e s3 nella stessa regione oppure tra dati ec2 in nother virginia e altre regioni.

S3 Masterclass

info useful:

  • rules of the read/write/delete slide 29
  • partition of data by optimization slide 41
  • move data between class storage by command line slide 59 by web interface slide 60
  • encryption page 64 , using a client sdk before upload
  • you can encrypt your data server side and there are 3 ways to manage the encryption keys

ways:

  1. SSE-SE slide 67 aws manage the key for you
  2. SSE-C slide 68 the customer manage the key and aws discard the key after the encryption
  3. SSE-KMS slide 69 use the key management system of aws, there are audit to see who is using the keys
  • other security system: audit logs, multi factor authentication to delete, time limited access object from slide 74 to 77 give access for a limited period of time
  • version , to access by command line to this feature you need the advanced command for s3 from the command line "aws s3api …. " from 82 to 87
  • cross region replication, when you enable from the webconsole a iam role for the action is created automatically to do the action
  • website hosting there are some examples of bucket redirect and also the use of s3 from slide 119 to 131

other things of s3 not covered:

  • cloudfront
  • event notification
  • lambda

another very good video about s3 is here https://www.youtube.com/watch?v=2DpOS0zu8O0&feature=youtu.be
AWS re:Invent 2014 | (SDD413) Amazon S3 Deep Dive and Best Practices

Amazon S3 Getting Started Guide

Questa guida http://docs.amazonwebservices.com/AmazonS3/latest/gsg/ è molto banale spiega solo come creare il primo bucket e come fare gli upload degli oggetti.

Amazon S3 Developer Guide

molto dettagliata per ora vediamo quella più essenziale che è la console user guide

Amazon S3 Console User Guide

Questa guida è più completa e da le informazioni importanti e necessarie per usarlo veramente.

Introduction to Amazon S3

  • Bucket: permettono di accedere agli oggetti che sono pubblici da fuori in questo modo http://nomebucket.s3.amazonaws.com/cartella/oggeto-per-esempio-una-img.jpg
  • oggetti: finchè si utilizza la console possono essere visti come file hanno dati e metadati.
  • folders: sono disponibili nella console ma non nelle api servono per raggruppare gli oggetti. Quando si crea una folder s3 crea un oggetto con zero byte e con una / alla fine del nome dell'oggetto. Amazon lo interpreta come delimitatore per una lista di operazioni.
  • keys la chiave identifica univocamente un oggetto ogni oggetto può essere identificato con web service endpoint, bucket name, key, and optionally, a version per prendere l'esempio di prima cartella/oggeto-per-esempio-una-img.jpg
  • regioni: ogni oggetto in una region non lascia mai quella region, a meno che si faccia la cosa esplicitamente.
  • access control: si può fare tramite acls e bucket policies

le operazioni sono fatte in maniera quasi atomica ci sono maggiori dettagli nella pagina ma non mi sembrano rilevanti.

Si paga mentre si consuma lo storage, non è necessario fare il provisioning.

Usare il bucket da una istanza amazon guarda anche sotto Access to bucket using utilities

Quello veramente utile che ho trovato con difficoltà è usare il bucket da una istanza amazon in modo da farci i backup dentro nel mio caso.
La guida di partenza è stato questo post https://forums.aws.amazon.com/thread.jspa?threadID=39361 io ho usato una ubuntu 12.04 per fare i test.

Rispetto al post ho scaricato una versione diversa del tool invece di prendere quella dei sorgenti ho preso l'ultima compilata che ho trovato dal sito http://code.google.com/p/s3fs/downloads/list

wget http://s3fs.googlecode.com/files/s3fs-1.25.tar.gz
tar xvzf s3fs-1.25.tar.gz
apt-get install build-essential libxml2-dev libfuse-dev libcurl4-openssl-dev
cd s3fs-1.25/
./configure; make; make install
touch /etc/passwd-s3fs
chmod 640 /etc/passwd-s3fs
nano /etc/passwd-s3fs

Dentro il file ho messo su una sola riga e divisi da : i codici Access Key ID Secret Access Key presi da https://portal.aws.amazon.com/gp/aws/securityCredentials
mkdir /mnt/bucket
s3fs nomedelmiobucket /mnt/bucket/

il nome del bucket è quello usato anche nella url
a questo punto dentro il bucket ci sono gli oggetti

Per montarlo in automatico tramite fstab

s3fs#backup /mnt/bucket fuse rw,uid=0,gid=0,auto,allow_other     0 0

Installare il bucket in una ubuntu 10.04

Ho preso le info da questa guida http://code.google.com/p/s3fs/issues/detail?id=143
Facendo la procedura sopra si ottiene un errore al configure che dice

Requested 'fuse >= 2.8.4' but version of fuse is 2.8.1

Si deve installarla manualmente ecco come fare

% wget http://sourceforge.net/projects/fuse/files/fuse-2.X/2.8.4/fuse-2.8.4.tar.gz/download
% tar xvzf fuse-2.8.4.tar.gz
% cd fuse-2.8.4
% ./configure --prefix=/usr
% make
% sudo make install

Dopo si può procedere come sopra.
La connessione al bucket funziona anche da macchine esterne ad amazon.

Access to bucket using utilities

Linux

I have used the s3cmd line utility with syncronizzation, very good documented in man page

dimension of a dir in the bucket

s3cmd du s3://bucketname/directory/subdir -H

syncronization of a directory, with log out

s3cmd sync /var/dir/localdir s3://buckename/dir/subdir/  >> /var/log/backup_to_s3.log 2>&1

Windows

I have used with success this utility http://s3.codeplex.com/ is a little exe and it's not necessary installation. Only download and execute

for syntax and info how to use

s3.exe help put

or other command

Create an user in amazon iam and give the necessary permission to the bucket/s, obtain access key id and access key secret

Connect to amazon account

s3.exe auth

respond N to the request of encrypt the key with a password
give the information key id and secret
try to list
s3.exe list

I have used the put command only with synchronization options for backup

s3.exe put bucket-name/directory/ c:\directory-to-sync\ /sync

in this way not sync subfolders there is an option to do this.

Create a static hosting with S3

there is this nice guide here https://blog.hartleybrody.com/static-site-s3/
you need to add the default bucket policy in the bucket properties , Permissions section, "add a bucket policy"

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucketname/*"
        }
    ]
}

I'm still looking to configure using a dns name http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

Give another account access to an your bucket

  • create the bucket
  • click to "Edit Bucket Policy" and assign this

replace the xxxxxxxx with the other account id

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Example permissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::xxxxxxxxxxxx:root"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mybucketname",
                "arn:aws:s3:::mybucketname/*"
            ]
        }
    ]
}

to test you need to have access from the other account and use a command like this
aws s3 cp --profile=otheraccount fileinmymachine.txt s3://mybucketname/

more detailed instructions here http://docs.aws.amazon.com/AmazonS3/latest/dev/example-walkthroughs-managing-access-example2.html

the user in the destination account needs to have a permission like this to access to the bucket

{
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::*"
        },
        {
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": [
                "arn:aws:s3:::mybucketname",
                "arn:aws:s3:::mybucketname/*"
            ]
        }
    ]
}

if you want share the bucket with multiple accounts you need to change the bucket policy editor in this way

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Example permissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::account-id1:root"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mybucketname",
                "arn:aws:s3:::mybucketname/*"
            ]
        },
        {
            "Sid": "Example permissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::account-id2:root"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::mybucketname",
                "arn:aws:s3:::mybucketname/*"
            ]
        }
    ]
}
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License