This lab covers
- Signup for AWS Free Tier Account
Note: You are responsible for your AWS Billing.
-
Login into AWS Console Homepage
-
Navigate to
Services > AWS Cost Management > AWS Budgets
-
Click on "Create budget"
-
Choose the following options
Budget setup = Use a template (simplified)
Templates - new = Zero spend budget
Budget name = My Zero-Spend Budget
Email recipients = "Enter email of all team members" -
Click on "Create budget"
Refer: https://docs.aws.amazon.com/cost-management/latest/userguide/budget-templates.html
-
Login into AWS Console Homepage
-
Navigate to
Services > Storage > S3
-
Click on "Create bucket"
-
Choose the following options
Bucket name = SomeBucketNameWhichIsUnique
AWS Region = us-east-1
ACLs disabled (recommended)
Uncheck - Block all public access
Rest with deafult options -
Click on "Create bucket"
-
Click on the created bucket
-
Choose
Permissions > Bucket Policy Edit > Policy Generator
Next:
Select Type of Policy = S3 Bucket Policy
Effect = Allow
Principle = *
Actions = GetObject
ARN = Copy from previous page and add '/*' at the endClick Add Statement
Generate Policy & Copy to clipboard
Paste under Policy & Save Changes
-
Login into AWS Console Homepage
-
Navigate to
Services > Security, Identity, & Compliance > IAM
-
Navigate to
Access management > Users ? Add users
-
Enter a user name
demowriteuseronly
-
Select
Permissions options = Attach policies directly
-
Select "Create policy"
-
Choose
Service = S3
Actions > Access Level = List + Read + tagging + Write
Resource >
Accesspoint = any
bucket = past you bucket ARN and Any
object = past you bucket ARN and Check Object name any -
Select Next > Next
-
Enter a policyname
name = bucketwritepolicy
-
Create Policy
-
After you return to orginal window check the policy created "bucketwritepolicy"
-
Click Next and Create User
-
Click on the created user
-
Navigate to
Security credentials > Access keys > Create access key
-
Select "Command Line Interface (CLI)" and check the I Agree & Next
-
Create Access key and Download .csv file for reference later
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2.
Links
-
Create a virtual environment and activate it
-
Install
boto3
python packagepip install boto3
-
Configure you AWS key from Step 16 above
One of the way is to use
python-dotenv
packagea. Create
.env
file along withmain.py
b. Paste the following into the
.env
fileAWS_ACCESS_KEY=your_aws_access_key AWS_SECRET_KEY=your_aws_secret_key
c. Install
python-dotenv
packagepip install python-dotenv
d. DONOT commit your
.env
file to gite. Refer to
main.py
futherimport os from dotenv import load_dotenv load_dotenv()
f. Access your env variables
os.environ.get('AWS_ACCESS_KEY')
-
Connect to boto client
s3client = boto3.client('s3', region_name='us-east-1', aws_access_key_id = os.environ.get('AWS_ACCESS_KEY'), aws_secret_access_key = os.environ.get('AWS_SECRET_KEY') )
-
More refer to functions within the script to access objects from buckets
list_files_in_user_bucket() list_files_in_noaa_bucket()