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
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.
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.Network settings
Edit
Keep the default VPC selection
Subnet: Choose the first subnet in the dropdown list
Auto-assign Public IP: Enable🖱️
Then expanding the advanced details section
under IAM instance profile choose S3DynamoDBFullAccessRole
pasting user data below (change
AWS_DEFAULT_REGION
)
click Launch instances
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.
This content originally appeared on DEV Community and was authored by JJ Chen
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.