Skip to content

Instantly share code, notes, and snippets.

@anneakin
Created May 23, 2020 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anneakin/db976d2d201bb795b72091dc5169d4be to your computer and use it in GitHub Desktop.
Save anneakin/db976d2d201bb795b72091dc5169d4be to your computer and use it in GitHub Desktop.
EC2 Instance resource with User Data
UserEc2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
IamInstanceProfile: !Ref EC2IamInstanceProfile
ImageId: ami-0a887e401f7654935
KeyName: !Ref UserKey
SubnetId: !Ref Subnet
Tags:
-
Key: Name
Value: !Join [ '-', [ !Ref Username, 'ec2-instance' ] ]
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
amazon-linux-extras install epel -y
yum install s3fs-fuse -y
chmod 777 /etc/fuse.conf
echo "user_allow_other" >> /etc/fuse.conf
mkdir /home/ec2-user/s3-mount
chmod 777 /home/ec2-user/s3-mount
chown -R $USER /home/ec2-user/s3-mount
cd /
s3fs ${UserS3Bucket} /home/ec2-user/s3-mount -o allow_other -o iam_role=${EC2IamRole} -o nonempty
chown -R ec2-user:ec2-user /tmp
chown -R ec2-user:ec2-user /home/ec2-user/s3-mount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment