def list(bucket_name=None): """List all buckets""" if bucket_name: pass else: bucket_iterator = BucketManager.all_buckets() for bucket in bucket_iterator.all(): print(bucket.name)
def cli(profile): """Webotron deploys websites to AWS.""" global session, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session)
def cli(profile): "Webotron deploys websites to AWS" global session, bucket_manager session_cfg = {} # session config dictionary if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session)
def cli(profile): # If profile name value, session config is assigned to that value global session, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session)
def cli(profile): """Webotron deploys websites to AWS.""" global SESSION, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile SESSION = boto3.Session(**session_cfg) # ** entpackt das dict bucket_manager = BucketManager(SESSION)
def cli(profile): """Webotron deploys websites to AWS.""" global SESSION, BUCKET_MANAGER session_cfg = {} if profile: session_cfg['profile_name'] = profile SESSION = boto3.Session( **session_cfg) #** unwrap the dictoronalr as a paratmer to function BUCKET_MANAGER = BucketManager(SESSION)
def cli(profile): """Webotron deploys website to aws""" global SESSION, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile SESSION = boto3.Session(**session_cfg) bucket_manager = BucketManager(SESSION)
def cli(profile, region): """Webotron deploys websites to AWS.""" global SESSION, BUCKET_MANAGER session_cfg = {} if profile: session_cfg['profile_name'] = profile session_cfg['region_name'] = region SESSION = boto3.Session(**session_cfg) BUCKET_MANAGER = BucketManager(SESSION)
def cli(profile): """Script deployes websites to AWS.""" global session, bucket_manager, domain_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session) domain_manager = DomainManager(session)
def cli(profile): """Webotron deploys websites to AWS""" global session, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile # '**' allows you to pass in a dictionary as an argument to a function session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session)
def cli(profile): """Webotron deploys websites to AWS.""" global session, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile else: session_cfg['profile_name'] = 'pythonAutomation' session = boto3.Session(**session_cfg) # Session(profile_name="pythonAutomation") bucket_manager = BucketManager(session)
def cli(profile): """Webotron deploys websites to AWS""" global session, bucket_manager, domain_manager, cert_manager, dist_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session) domain_manager = DomainManager(session) cert_manager = CertificateManager(session) dist_manager = DistributionManager(session)
def cli(profile): "webtron deploys website to AWS" global session, bucket_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager( session) #s3 = session.resource('s3') defined in bucket.py
def cli(profile): """Webotron deploys websites to AWS.""" global session, bucket_manager, domain_manager, util_manager session_cfg = {} if profile: session_cfg['profile_name'] = profile else: session_cfg['profile_name'] = 'pythonAutomation' session = boto3.Session(**session_cfg) # glob that will unwrap to fit func bucket_manager = BucketManager(session) domain_manager = DomainManager(session) util_manager = UtilManager()
def cli(profile): """Deploys websites to AWS.""" global SESSION, BUCKET_MANAGER, DOMAIN_MANAGER, CERT_MANAGER, DIST_MANAGER session_cfg = {} if profile: session_cfg['profile_name'] = profile session_cfg['region_name'] = 'eu-west-2' SESSION = boto3.Session(**session_cfg) BUCKET_MANAGER = BucketManager(SESSION) DOMAIN_MANAGER = DomainManager(SESSION) CERT_MANAGER = CertificateManager(SESSION) DIST_MANAGER = DistributionManager(SESSION)
def cli(profile): """Webotron deploys websites to AWS.""" """Makes these variables global.""" global session, bucket_manager """Sets which session will be used.""" session_cfg = {} if profile: session_cfg['profile_name'] = profile """***session_cfg will decouple the dictionary and make it easy to pass as a param.""" session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session)
def cli(profile): """This script executes various commands for S3""" global session, bucket_manager, domain_manager, certificate_manager, dist_manager session_cfg = {} if (profile): session_cfg['profile_name'] = profile session = boto3.Session(**session_cfg) bucket_manager = BucketManager(session) domain_manager = DomainManager(session) certificate_manager = CertificateManager(session) dist_manager = DistributionManager(session)
def cli(profile): # only when the group takes over """Webotron deploys websites to AWS.""" # profile name configuration. let user pass in the profile global session, bucket_manager # to reset them here session_cfg={} # dictionary if profile: session_cfg['profile_name'] = profile session=boto3.Session(**session_cfg) # glob? #profile_name='pythonAutomation' bucket_manager = BucketManager(session) ## bucket manager will later hold S3 resource pass
def cli(profile): """We3botron deploys websites to AWS""" # makes the varibles session and #bucket_manager available in all parts of the script global session, bucket_manager # creating session dictionary session_cfg = {} if profile: session_cfg['profile_name'] = profile # create Session # profile_name='pythonAutomation' session = boto3.Session(**session_cfg) # ** function wrapper will unrole the diction that was created above bucket_manager = BucketManager(session) # s3 = session.resource('s3') Bucket Manager will hold the S3 Resource pass
- List bucket - List bucket objects - Create and setup bucket """ import mimetypes from pathlib import Path import boto3 from botocore.exceptions import ClientError import click from bucket import BucketManager session = boto3.Session() bucket_manager = BucketManager(session) #s3 = session.resource('s3') @click.group() def cli(): """Webotron deploys websites to AWS""" pass @cli.command('list-buckets') def list_buckets(): """List all s3 buckets""" for bucket in bucket_manager.all_buckets(): print(bucket)
def setup_bucket(bucket): """Create and configure S3 bucket.""" s3_bucket = BUCKET_MANAGER.init_bucket(bucket) BucketManager.set_policy(s3_bucket) BucketManager.configure_website(s3_bucket)
# -*- coding: utf-8 -*- """Webotron: Deploy websites to s3 buckets.""" from pathlib import Path from mimetypes import guess_type import boto3 from botocore.exceptions import ClientError import click from bucket import BucketManager SESSION = boto3.Session(profile_name='sandbox') bucket_manager = BucketManager(SESSION) #s3 = SESSION.resource('s3') def upload_file(s3bucket, path, key): """Upload path to s3 bucket at key.""" content_type = guess_type(key)[0] or 'text/html' s3bucket.upload_file(path, key, ExtraArgs={'ContentType': content_type}) @click.group() def cli(): """Webotron uploads websites to AWS S3.""" @cli.command('list-buckets') def list_buckets(): """List buckets.""" for bucket in bucket_manager.all_buckets(): print(bucket)
def setup_bucket(bucket): """Create and setup an bucket_manager.s3 bucket.""" s3_bucket = bucket_manager.init_bucket(bucket) BucketManager.set_policy(s3_bucket) BucketManager.configure_website(s3_bucket)
try: session = boto3.Session(profile_name=profile_name) except: profile_list = os.system('cat ~/.aws/config') profile_list = subprocess.run( ["cat ~/.aws/config"], stdout=subprocess.PIPE, text=True, input="All available profiles are bellow: \n") print(profile_list.stdout) print("Session creation failed for the following profile : \n", profile_name) print("Please use current profile name from the available bellow: \n", profile_list.stdout) bucket_manager = BucketManager(session) # def setup_bucket(bucket_name): s3_bucket = bucket_manager.init_bucket(bucket_name) bucket_manager.set_policy(bucket_name, s3_bucket) bucket_manager.configure_website(s3_bucket) # Print out the website URL: url = f'http://{bucket_name}.s3-website-us-east-1.amazonaws.com/' print(url) return # def sync(pathname, bucket_name):
import boto3 import click from botocore.exceptions import ClientError from pathlib import Path import mimetypes from bucket import BucketManager from domain import DomainManager from certificate import CertificateManager from cloudfront import CDNManager session = boto3.Session(profile_name='pythonAutomation') bucket_manager = BucketManager(session) #object of class domain_manager = DomainManager(session) cert_manager = CertificateManager(session) cdn_manager = CDNManager(session) @click.group() def cli(): "Webotron deploys websites to AWS" pass @cli.command('list-buckets') def list_buckets(): "list all s3 buckets" for i in bucket_manager.list_all_buckets(): print(i) @cli.command('list-bucket-objects')
aws_region = args.Region if args.Website_Root: website_root_path = args.Website_Root if args.AWS_Profile: aws_profile = args.AWS_Profile if args.Site_DNS: site_dns = args.Site_DNS if args.Domain: domain_name = args.Domain # Setting Boto3 session # programmatically authenticate to AWS via boto3 session = boto3.Session(profile_name=aws_profile, region_name='us-west-2') # Various service objects using their respective classes bucket_manager = BucketManager( session) # creating an S3 bucket_manager object from BucketManager class domain_manager = DomainManager( session) # creating a route53 domain_manager object cert_manager = CertificateManager( session) # creating a certificate manager object dist_manager = DistributionManager(session) def list_buckets(): """List all S3 Buckets.""" for bucket in bucket_manager.all_buckets( ): # calling the all_buckets method print(bucket) def list_bucket_objects(bucket):