From 1f20dce908e6eac7e637c3cddb20ee4c0edf18d5 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 1 Oct 2020 20:15:53 -0400 Subject: [PATCH] Fix #236: Script to Create an Amazon S3 Bucket --- .../Amazon-Bucket-Creator/README.md | 18 ++++++++++++++++ .../Amazon-Bucket-Creator/defaults.py | 7 +++++++ .../Amazon-Bucket-Creator/main.py | 21 +++++++++++++++++++ .../Amazon-Bucket-Creator/requirements.txt | 1 + 4 files changed, 47 insertions(+) create mode 100644 System-Automation-Scripts/Amazon-Bucket-Creator/README.md create mode 100644 System-Automation-Scripts/Amazon-Bucket-Creator/defaults.py create mode 100644 System-Automation-Scripts/Amazon-Bucket-Creator/main.py create mode 100644 System-Automation-Scripts/Amazon-Bucket-Creator/requirements.txt diff --git a/System-Automation-Scripts/Amazon-Bucket-Creator/README.md b/System-Automation-Scripts/Amazon-Bucket-Creator/README.md new file mode 100644 index 00000000..877bab8e --- /dev/null +++ b/System-Automation-Scripts/Amazon-Bucket-Creator/README.md @@ -0,0 +1,18 @@ +## Automate AWS S3 Bucket +- This script can be used to create a bucket in aws simply and quickly. +- To do this, the **boto** library is used + +## AWS KEYS +- To get the **aws_access_key_id_value** and **aws_secret_access_key_value** keys go to the AWS panel (https://console.aws.amazon.com/) +- Go to your user's menu and access My Security Credentials +- Then create a new access key, so it is presented **aws_access_key_id_value** and **aws_secret_access_key_value** +- After that, just replace it in the defaults.py file + +## AWS REGIONS +- https://howto.lintel.in/list-of-aws-regions-and-availability-zones/ + +## INSTALL DEPENDENCIES +- Just run: pip install -r requirements.txt + +## Working +- After configuring the defauls just run the main file :) \ No newline at end of file diff --git a/System-Automation-Scripts/Amazon-Bucket-Creator/defaults.py b/System-Automation-Scripts/Amazon-Bucket-Creator/defaults.py new file mode 100644 index 00000000..6cddd61f --- /dev/null +++ b/System-Automation-Scripts/Amazon-Bucket-Creator/defaults.py @@ -0,0 +1,7 @@ +AMAZON_SECRETS = { + 'service': 's3', + 'aws_access_key_id_value': 'YOUR-ACCESS-KEY-OF-THE-AWS-ACCOUNT', + 'aws_secret_access_key_value': '', + 'bucket_value': '', + 'location_constraint_value': '' +} \ No newline at end of file diff --git a/System-Automation-Scripts/Amazon-Bucket-Creator/main.py b/System-Automation-Scripts/Amazon-Bucket-Creator/main.py new file mode 100644 index 00000000..28f1124f --- /dev/null +++ b/System-Automation-Scripts/Amazon-Bucket-Creator/main.py @@ -0,0 +1,21 @@ +#!/bin/python3 + +import boto3 +from botocore.exceptions import ClientError +from defaults import AMAZON_SECRETS + + +client = boto3.client(AMAZON_SECRETS.get('service'), + aws_access_key_id=AMAZON_SECRETS.get('aws_access_key_id_value'), + aws_secret_access_key=AMAZON_SECRETS.get('aws_secret_access_key_value')) + +try: + bucket = client.create_bucket(Bucket=AMAZON_SECRETS.get('bucket_value'), + CreateBucketConfiguration={ + 'LocationConstraint': AMAZON_SECRETS.get('location_constraint_value') + }) +except ClientError as error: + print(f'[-] Error: {error}') +else: + print(f'[+] {AMAZON_SECRETS.get("bucket_value")} successfully created!') + print(f'[+] Location: {bucket.get("Location")}') diff --git a/System-Automation-Scripts/Amazon-Bucket-Creator/requirements.txt b/System-Automation-Scripts/Amazon-Bucket-Creator/requirements.txt new file mode 100644 index 00000000..64f90ba8 --- /dev/null +++ b/System-Automation-Scripts/Amazon-Bucket-Creator/requirements.txt @@ -0,0 +1 @@ +boto3==1.15.10