Skip to main content

Initialising EC2 with userdata script​

This guide will help you to initialise the EC2 instance with ngnix when configuring the EC2 instance.

When creating the instance insert the following script in

Advance Settings > User data

#!/bin/bash
apt-get update
apt-get install -y nginx awscli curl redis-server certbot python3-certbot-nginx python3-pip build-essential libssl-dev libffi-dev python3-venv wget vim
systemctl start nginx
systemctl enable nginx
systemctl reload ngnix

## Skip redis if not needed
systemctl start redis-server
systemctl enable redis-server

This script will install other dependencies as well which are suitable when initialising the instance the first time.


S3 Single Bucket Access policy​

This policy allows the role with only single bucket access.

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::<s3-bucket-name>"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:PutObjectAcl",
"s3:ListBucketMultipartUploads",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:GetEncryptionConfiguration"
],
"Resource": [
"arn:aws:s3:::<s3-bucket-name>,
"arn:aws:s3:::<s3-bucket-name>/*"
]
}
]
}