Use EC2 user data script run a flask app🌐

Creating Employee Directory Application automatically with AWS

🔥You can create an EC2 Amazon Linux 2023 user data script
It will run script after you start EC2.

Launch EC2 instance

select the Amazon Machine Image
Amazon Machine I…


This content originally appeared on DEV Community and was authored by JJ Chen

Creating Employee Directory Application automatically with AWS

🔥You can create an EC2 Amazon Linux 2023 user data script
It will run script after you start EC2.

Launch EC2 instance

  1. select the Amazon Machine Image
    Amazon Machine Images can come from AWS, like this Amazon Linux 2023 AMI, for example. This is the one that we will be using, but you can also browse more AMIs that would include AMIs coming from the AWS Marketplace.
    Image description

  2. just a lab, you can choose free tier eligible
    Image description

  3. Next, we have to decide if we want to configure a key pair.
    We are going to select that we are going to proceed without a key pair for this, and the reason for that is because I don't intend to SSH into this instance to connect to it.

  4. Network settings
    Edit Keep the default VPC selection
    Subnet: Choose the first subnet in the dropdown list
    Auto-assign Public IP: Enable🖱️
    Image description
    Image description

  5. Then expanding the advanced details section
    under IAM instance profile choose S3DynamoDBFullAccessRole
    Image description

  6. pasting user data below (change AWS_DEFAULT_REGION)
    click Launch instances
    Image description

For Amazon Linux 2023

#!/bin/bash -ex
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/FlaskApp.zip
unzip FlaskApp.zip
cd FlaskApp/
yum -y install python3-pip
pip install -r requirements.txt
yum -y install stress
export PHOTOS_BUCKET=${SUB_PHOTOS_BUCKET}
export AWS_DEFAULT_REGION=ap-northeast-1
export DYNAMO_MODE=on
FLASK_APP=application.py /usr/local/bin/flask run --host=0.0.0.0 --port=80 

For Amazon Linux 2

#!/bin/bash -ex
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/FlaskApp.zip
unzip FlaskApp.zip
cd FlaskApp/
yum -y install python3 mysql
pip3 install -r requirements.txt
amazon-linux-extras install epel
yum -y install stress
export PHOTOS_BUCKET=${SUB_PHOTOS_BUCKET}
export AWS_DEFAULT_REGION=<INSERT REGION HERE>
export DYNAMO_MODE=on
FLASK_APP=application.py /usr/local/bin/flask run --host=0.0.0.0 --port=80

open address🔚

your Employee Directory Application running~
when you start the instance, the script will execute.

Image description

Image description


This content originally appeared on DEV Community and was authored by JJ Chen


Print Share Comment Cite Upload Translate Updates
APA

JJ Chen | Sciencx (2024-08-19T02:16:59+00:00) Use EC2 user data script run a flask app🌐. Retrieved from https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/

MLA
" » Use EC2 user data script run a flask app🌐." JJ Chen | Sciencx - Monday August 19, 2024, https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/
HARVARD
JJ Chen | Sciencx Monday August 19, 2024 » Use EC2 user data script run a flask app🌐., viewed ,<https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/>
VANCOUVER
JJ Chen | Sciencx - » Use EC2 user data script run a flask app🌐. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/
CHICAGO
" » Use EC2 user data script run a flask app🌐." JJ Chen | Sciencx - Accessed . https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/
IEEE
" » Use EC2 user data script run a flask app🌐." JJ Chen | Sciencx [Online]. Available: https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/. [Accessed: ]
rf:citation
» Use EC2 user data script run a flask app🌐 | JJ Chen | Sciencx | https://www.scien.cx/2024/08/19/use-ec2-user-data-script-run-a-flask-app%f0%9f%8c%90/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.