S n a k e s o n a C l o u d P y t h o n , B o t o 3 , a n d G e t t i n g T h i n g s D o n e
We l c o m e B u f f a l o P y t h o n i s t a s ryansb@redhat.com Ryan Scott Brown @ryan_sb Senior Software Engineer Ansible by Red Hat
A g e n d a ● Setup & Basics ● Talking to Instances ● In-Application Use ● Ops, Automation, and Hacking the Planet ● Testing (if there’s time)
S e t u p ● Installing ● Credentials/Profiles ● Hello World
I n s t a l l i n g pip install boto3 pip install awscli #optional aws configure --profile testbed #optional
C r e d e n t i a l s # ~/.aws/credentials [testbed] aws_access_key_id = AKIA… aws_secret_access_key = Jhw…
C r e d e n t i a l S o u r c e s ● Instance roles ● Environment variables ● Access/Secret key pair ● Access + secret + session using STS ● Credentials files ● Assuming cross-account roles
I n s t a n c e R o l e s GET http://169.254.169.254/…./credentials Your AWS Backplane Instance Key ID+Secret+Session Token+TTL
C r o s s - A c c o u n t R o l e s AssumeRole arn:aws:….:SuperAdmin Key ID + Secret Your IAM API Client Key ID+Secret+Session Token+TTL
H e l l o Wo r l d aws s3 ls
H e l l o Wo r l d >>> import boto3 >>> s3 = boto3.client(‘s3’) >>> print(s3.list_buckets())
S e s s i o n s ● Typically 1 is plenty ● If you have multi-region or user requirements, these handle it well ● `session.client(‘service’)` works instead of the default `boto3.client(‘service’)`
S 3 D e m o N o t e b o o k Download notebook file Browser-friendly results
C l i e n t s v s . R e s o u r c e s ● Clients are lower-level and usually map 1:1 with APIs ● Resources are built around first-class objects ● Services always have clients, sometimes have resources ● DynamoDB, S3, CloudFormation, and others have both
H i g h L e v e l S e r v i c e s ● App-level services like DynamoDB + S3 ● Accept user uploads ● Generate pre-signed URLs ● Store and query key-value data
D y n a m o D B D e m o N o t e b o o k Download Notebook File Browser-friendly results
C o n n e c t i n g t h e P l a n e t ● What if you combined dataviz with infra data? ● Networkx (graph handling library) can export visual graphs b
E C 2 D e m o N o t e b o o k Download notebook file Browser-friendly results
H a c k i n g t h e P l a n e t ● Python can be used in combination with other tools ● Have a bunch of CloudFormation? No problem – https://github.com/ryansb/yesterdaytabase ● Ansible? Make a module! ● Chef/Puppet? Mix user-data+boto3+Chef Solo/OpsWorks
E x t e n d i n g C l o u d F o r m a t i o n ● AWS Lambda can be used for custom resources – https://github.com/ryansb/acm-certs-cloudformation – https://github.com/ryansb/cfn-wrapper-python ● Expose Custom::YourThing interface to templates ● Anything boto3 supports, you can add to CloudFormation
Q u e s t i o n T i m e !
Recommend
More recommend