Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

44
Formation Interface ligne de commande

Transcript of Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Page 1: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Formation

Interface ligne de commande

Page 2: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

AWS EN LIGNE COMMANDE

Formation AWS CLI

2

Page 3: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Plan• Présentation des différents outils• EC2 API/AMI tools• Euca2ools• S3cmd• AWS CLI

Formation AWS CLI

3

Page 4: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

PRÉSENTATION DES DIFFÉRENTS OUTILS

Formation AWS CLI

4

Page 5: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Panorama (1)• Pas (encore) d'outils en ligne de commande supportés officiellement par Amazon• EC2 API/AMI/etc. Tools (AWS)

• En java pour la plupart• Un ensemble de commandes peu cohérent

• AWS CLI (AWS)• Ligne de commande unifiée pour gérer l'ensemble des

services AWS• Developer preview

Formation AWS CLI

5

Page 6: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Panorama (2)• Euca2ools (Eucalyptus/communautaire)

• Développé à l'origine pour Eucalyptus (Open Source)• Compatible AWS, OpenStack, OpenNebula

• S3cmd (communautaire)• Utilitaire dédié à S3• Le couteau suisse pour manipuler S3

Formation AWS CLI

6

Page 7: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Récupérer ses identifiants AWS (1)• Compte Amazon : compte Maître, à ne pas utiliser en production !• Pour la production, utiliser le service IAM pour générer des identifiants avec des ACL réduits• Identifiants AWS: une paire de clés d'accès

• Identifiant de clé d'accès• Clé d'accès secrète

Formation AWS CLI

7

Page 8: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Récupérer ses identifiants AWS (2)• Certificats X.509

• Nécessaire pour signer les AMI • Nécessaire pour accéder à l'API SOAP (déconseillé)• Limité à 2 par compte !

• Les identifiants et certificats ne peuvent être récupérés qu'à la création par mesure de sécurité• Attention !

• En cas de perte d'identifiants, désactiver les clés et regénérer en de nouveaux !

Formation AWS CLI

8

Page 9: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Récupérer ses identifiants AWS (3)1. Se connecter à la console d'administration

https://aws.amazon.com2. Aller sur l'onglet « Compte/Console » puis cliquer sur

l'entrée « AWS Management Console » 3. Se connecter avec son compte Amazon4. Cliquer sur « security credentials »5. Créer une paire de clés d'accès identifiant de clé d'accès/clé

d'accès secrète6. Créer un certificat X.509 pour signer vos AMI

Formation AWS CLI

9

Page 10: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Récupérer ses identifiants AWS (3)1. Dans la console AWS, se connecter au service IAM2. Aller dans le menu « users »3. Cliquer sur le bouton « Create users »4. Récupérer le fichier CSV contenant les identifiants

Formation AWS CLI

10

Page 11: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Démo IAM

Formation AWS CLI

11

Page 12: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

EC2 API/AMI TOOLS

Formation AWS CLI

12

Page 13: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Installation• Télécharger les EC2 API Tools https://aws.amazon.com/developertools/351

• Télécharger les EC2 AMI Toolshttps://aws.amazon.com/developertools/368

Formation AWS CLI

13

Page 14: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Configuration• Configurer les variables d'environnement :

• export EC2_HOME=/opt/ec2-api-tools-xxxx • export EC2_AMITOOL_HOME=/opt/ec2-ami-tools-xxx• export PATH=$EC2_HOME/bin:$EC2_AMITOOL_HOME/bin:$PATH

• export AWS_ACCESS_KEY=XXXX• export AWS_SECRET_KEY=XXXX

• On peut également les passer en ligne de commande avec respectivement les options --aws-access-key et --aws-secret-key (ou -O et -W)

Formation AWS CLI

14

Page 15: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (1)• Démarrer une instance

ec2-run-instances <ami-xxx> -k <cle-ssh> -t <instance-type> [-g <security-group>]

• Lister les instancesec2-describe-instances –region eu-west-1

• Arrêter une instanceec2-terminate-instances <liste instance-id>

Formation AWS CLI

15

Page 16: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (2)• Créer un groupe de sécurité

ec2-create-group ssh-access -d <description>

• Ajouter une règle au groupe de sécuritéec2-authorize ssh-access -P tcp -p 22 [-s ip]

• Supprimer une règle du groupe de sécuritéec2-revoke -P tcp -p 22

Formation AWS CLI

16

Page 17: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Euca2ools

Formation AWS CLI

17

Page 18: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Contexte• Développé par Eucalyptus• Interaction avec des services web compatibles EC2 et S3

(Eucalyptus/Walrus)• Inspiré par les ec2-{api,ami}-tools

Formation AWS CLI

18

Page 19: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Installation• Via le gestionnaire de paquetages de votre distribution

• apt-get install euca2ools• yum install euca2ools

• Manuelle (nécessite d'avoir Python 2.6+, Boto, M2Crypto d'installé)http://open.eucalyptus.com/wiki/Euca2oolsSourceInstall

• Via le Cheese Shop (aka PyPI)virtualenv euca2ools && cd euca2ools && source bin/activate && pip install euca2ools

Formation AWS CLI

19

Page 20: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Configuration • Via les variables d'environnements

• export EC2_ACCESS_KEY=XXXX• export EC2_SECRET_KEY=XXXX• export EC2_CERT=XXX

• Via le fichier de configuration « $HOME/.eucarc »EC2_REGION=eu-west-1EC2_ACCESS_KEY=XXXXEC2_SECRET_KEY=XXXXEC2_URL=https://ec2.${EC2_REGION}.amazonaws.com

Formation AWS CLI

20

Page 21: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Utilitaires • Lister les régions

euca-describe-regions

• Lister les zones de disponibilité au sein d'une régioneuca-describe-availability-zones

Formation AWS CLI

21

Page 22: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gestion paire de clés ssh • Créer une paire de clés ssh

euca-create-keypair <nom-paire-clés> 

• Importer une clé ssh publique existante euca-import-keypair -f <clé-publique> <nom-

paire-clé> 

• Lister les paires de clés euca-describe-keypairs

Formation AWS CLI

22

Page 23: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gestion d'instances EC2 (1) • Lister les instances

euca-describe-instances

• Récupérer les infos sur une instanceeuca-describe-instances <id>

• Démarrer une instance euca-run-instances <ami_id> \

--region eu-west-1 -g ssh-access \

-k mykey -f initscript.sh -n 4

Formation AWS CLI

23

Page 24: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gestion d'instances EC2 (2) • Mettre en pause une instance (EBS)

euca-stop-instance <id>

• Relancer une instance en pause (EBS)euca-start-instance <id>

• Arrêter une instanceeuca-terminate-instance <id>

• Redémarrer une instance (EBS) euca-reboot-instance <id>

Formation AWS CLI

24

Page 25: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gestion d'instances EC2 (3) • Se connecter à une instance EC2 via ssh

ssh -i mykey.pem ec2-user@<dns-publique-instance>

Formation AWS CLI

25

Page 26: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Réseau (1)• Créer un groupe de sécurité

euca-create-group prod

• Ajouter une règle dans le groupe de sécuritéeuca-authorize prod -P tcp -p 80 -s 0.0.0.0/0

• Supprimer une règle du groupe de sécurité euca-revoke prod -P tcp -p 80 -s 0.0.0.0/0

• Ajouter une règle pour ouvrir un port pour un groupe de sécurité

euca-authorize database -P tcp -p 5432 \-o prod

Formation AWS CLI

26

Page 27: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Réseau (2)• Supprimer un groupe de sécurité

euca-delete-group prod• Allouer une adresse IP fixe

euca-allocate-address • Associer une adresse IP fixe à une instance

euca-associate-address -i <id> <ip> • Casser l'association d'une adresse IP fixe d'une instance

euca-deassociate <ip>• Libérer une adresse IP fixe

euca-release-adress <ip>

Formation AWS CLI

27

Page 28: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gérer les volumes blocs (1)• Créer un volume bloc

euca-create-volume --zone <zone> --size 8

• Amarrer un volume à une instance euca-attach-volume -i <id> -d /dev/sdb <volume-id>

• Détacher un volume d'une instanceeuca-detach-volume -i <id> <volume-id>

• Détacher un volume de toutes les instanceseuca-detach-volume <volume-id>

• Supprimer un volume bloceuca-delete-volume <volume-id>

Formation AWS CLI

28

Page 29: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gérer les volumes blocs (2)• Créer un snapshot (doit être en état « in-use » ou « available »)

euca-create-snaphot <volume-id>• Créer un nouveau volume à partir d'un snapshot

euca-create-volume --zone <zone> --snapshot <snapshot-id>

• Vérifier l'état d'un snapshoteuca-describe-snapshots <volume-id>

• Supprimer un snapshoteuca-delete-snapshot <volume-id>

Formation AWS CLI

29

Page 30: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Gérer les volumes blocs (3)• Une fois attaché, le volume doit-être formaté et monté

mkfs.ext4 /dev/sdb && mount /dev/sdb/ /mnt/disk1

• Il est préférable de démonter un volume pendant la création d'un snapshot pour éviter les corruptions de données

Formation AWS CLI

30

Page 31: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

S3Cmd

Formation AWS CLI

31

Page 32: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Contexte• Amazon S3 : un service de stockage à prix raisonnable• Très populaire pour servir, partager et archiver des fichiers• S3cmd : couteau suisse pour gérer Amazon S3

Formation AWS CLI

32

Page 33: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Configuration• Utilisez l'assistant interactif !

s3cmd --configure

• Configuration stocké dans le fichier $HOME/.s3cfg

Formation AWS CLI

33

Page 34: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (1)• Lister les buckets

s3cmd ls

• Créer un bucket s3cmd mb s3://sysfera-test

• Lister le contenu d'un bucket s3cmd ls S3://sysfera-test

Formation AWS CLI

34

Page 35: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (2)• Upload d'un fichier

s3cmd put boto.jpg s3://sysfera-test

• Upload d'un fichier publique s3cmd put --acl-public --guess-mime boto.jpg

s3://sysfera-test

• Télécharger un fichier s3cmd get s3://sysfera-test/boto.jpg

Formation AWS CLI

35

Page 36: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (3)• Suppression d'un fichier

s3cmd del s3://sysfera-test/boto.jpg 

• Suppression d'un bucket (doit être vide)

s3cmd rb s3://sysfera-test 

• Copier un fichier :

s3cmd cp s3://sysfera-test/boto.jpg s3://sysfera-prod/ 

• Déplacer/renommer un fichier

s3cmd mv s3://sysfera-test/boto.jpg s3://sysfera-prod/boto.jpg 

Formation AWS CLI

36

Page 37: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Quelques commandes (4)• Récupérer information sur un fichier

s3cmd info s3://sysfera-test/boto.jpg

• Visualiser l'espace disque consommé s3cmd du s3://sysfera-test

• Synchroniser un répertoire avec un bucket s3cmd sync test/ s3://sysfera-test/

Formation AWS CLI

37

Page 38: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

AWS CLI

Formation AWS CLI

38

Page 39: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Contexte• Client unifié pour l'ensemble des services AWS• Basé sur Python 2/3 et la bibliothèque botocore• Developer preview actuellement• Sémantique simple

aws <service> <commande> <options>

• Prends en entrée des données au format JSON• Sortie formatée en JSON par défaut

Formation AWS CLI

39

Page 40: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Installation•Via le Cheese Shop (aka PyPI)

virtualenv awscli && cd awscli && source bin/activate && pip install awscli

Formation AWS CLI

40

Page 41: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Configuration (1)• Via un fichier de configuration

• Gère différents profils (option --profile)

• Accessible via une variable d'environnementexport AWS_CONFIG_FILE=$HOME/.awscli

Formation AWS CLI

41

Page 42: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Configuration (2)[default]aws_access_key_id=<default access key>aws_secret_access_key=<default secret key>region=us-west-1 # optional, to define default region for this profile

[testing]aws_access_key_id=<testing access key>aws_secret_access_key=<testing secret key>region=us-west-2

Formation AWS CLI

42

Page 43: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Comparatifs des différents outils

Formation AWS CLI

43

Page 44: Formation Interface ligne de commande. AWS EN LIGNE COMMANDE Formation AWSCLI 2.

Comparatif

Formation AWS CLI

44

statut Mainteneur Langage

ec2-api-tools mature AWS Java

ec2-ami-tools mature AWS Ruby

elb-api-tools mature AWS Java

euca2ools mature Eucalyptus Python

s3cmd mature communauté Python

AWS CLI Developer Preview

AWS Python