Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Fix #236: Script to Create an Amazon S3 Bucket #319

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions System-Automation-Scripts/Amazon-Bucket-Creator/README.md
Original file line number Diff line number Diff line change
@@ -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 :)
7 changes: 7 additions & 0 deletions System-Automation-Scripts/Amazon-Bucket-Creator/defaults.py
Original file line number Diff line number Diff line change
@@ -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': '<YOUR-SECRETE-KEY-OF-THE-AWS-ACCOUNT>',
'bucket_value': '<YOUR-S3-BUCKET-NAME>',
'location_constraint_value': '<YOUR-REGION-FOR-S3-BUCKET>'
}
21 changes: 21 additions & 0 deletions System-Automation-Scripts/Amazon-Bucket-Creator/main.py
Original file line number Diff line number Diff line change
@@ -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")}')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3==1.15.10