Step-By-Step Guide: Accessing S3 objects via S3 Pre-signed URLs

Accessing S3 objects via S3 Pre-signed URLs generated using Python Flask Server deployed on Amazon Ec2 instance.

High-level Architecture

Step 0. Create an S3 bucket, copy the Image file and the code

a. Create an S3 bucket named pre-signed-url-bucket

b. Create a file pre_signed_url.py on your local with the following content

c. Copy the file pre_signed_url.py and the image sample.png to pre-signed-url-bucket

Step 1. Launch an EC2 Instance

a. Launch an EC2 instance with the following config

Name: Flask Server

b. Create a Key pair with pem extension

c. Create a Security Group and a Security Group Rule to allow incoming SSH and Custom TCP (port 5000) traffic

d. Launch Instance

Step 2. Connect and Install Python and Virtualenv on E2 Instance

a. Connect to the EC2 Instance

b.

c. Install Python and Virtualenv

Step 3. Copy the image file and the code from S3 to the EC2 instance

Note

If you get “fatal error: Unable to locate credentials” try running the following and check the output

if the credentials are not set, set the credentials using the following command

Step 4. Run your Flask Web Application Server

Step 5. Access the Image from the browser

http://<your_ec2_instance_public_ip>:5000

https://stackoverflow.com/questions/67218285/trying-to-install-pip3-in-amazon-linux-2

https://repost.aws/knowledge-center/s3-locate-credentials-error

Rate this post

Leave a Reply