AeJey February 2016

Amazon AWS Cloudformation JSON template to assign the LAMP www/html folder permissions to ec2-user

I have created a JSON template to create the Amazon AWS LAMP stack with RDS (free tier) and succeffully created the stack. But when I tried to move the files to the var/www/html folder it seems to have no permission for the ec2-user. I know changing permission with help of SSH. But my intention is to create a template to setup a stack (hosting environment) without using any ssh client.

Also I know how to add a file or copy a zipped source to var/ww/html with the cloudformation JSON templating. What need to do is, just create the environment and later upload the files using ftp client and db using workbench or something. Please help me attain my goal, which I will share publicly for AWS beginners who are not familiar with setting up things with SSH.

The JSON template is a bit lengthy and so here is the link to the code http://pasted.co/803836f5

Answers


Vorsprung February 2016

tar files and distribution dependent files like .deb or .rpm include the file permissions for directories. So you could set up a tar or custom .rpm file to include ec2-user as the owner

Alternatively, whatever scripting element installs the apache could also run a set of updates to set the owner of the /var/www/html to ec2-user

Of course you might run into trouble with the User / Group that apache runs under and be able to upload with ftp but not able to read with apache. It would need some thought, and possibly adding the ec2-user to the apache group or ftp'ing as the apache user or some other combination that gives the ttpd server read access and the ssh user write access


Paul Dunlop February 2016

use the Cloud formation init Meta instead of Userdata.

That way you can run commands on the server such as pulling down files from S3 and then running gzip to expand them.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html

Post Status

Asked in February 2016
Viewed 1,896 times
Voted 11
Answered 2 times

Search




Leave an answer