Instead of logging into each EC2 instance and installing the application, it would be really nice if I can simply deploy the application on VM on start up. I can then deploy many VMs with the application with little manual intervention.
In this port I am going to do just that!
Moving the deployment files to Simple Storage Service (S3)
The first step is to create a bucket and upload the files to this bucket. I have called this bucket "simpleapistartup". I can simply use the "Upload" button to upload the files to the bucket.
The WebDeploy packages uploaded to S3 |
Copying the installation files from S3 to EC2 instance
The IAM role can only be associated with an EC2 instance at launch time and not when it is in running state.
I have created the role "S3ApiDeployment" that has full access to S3 and associated it with the new instance.
Associating the role when launching a new EC2 instance |
The next step is to provide the initialisation script to download the files from S3 to the C:\Deployment folder in the EC2 instance.
The AWS Command Line Interface (CLI)
The first step is to download the AWS CLI from here. There are multiple flavours and I have chosen the CLI for Windows. Once installed I can execute commands such as the following to access S3.
- aws s3 ls - lists all the buckets from S3
The plan is to run a script at VM boot time to download the files from S3. The following script copies the "simpleapistartup" bucket content including subdirectories to c:\Deployment folder.
- aws s3 cp s3://simpleapistartup/ c://deployment/ --recursive
EC2 User data
The installation script is passed to the an EC2 instance through Instance User data. The User data is set during an EC2 provisioning stage. See the following screen capture.
Setting initialisation script through User data |
The AWS CLI script needs to be wrapped in "<script>" or "<powershell>" tags. See the following.
I decided to use "<powershell>" tag because I plan to include Powershell commandlets in the future.
OK!, this is enough for this post. In the next post I will launch an EC2 instance which will run the above script to copy the deployment files from S3.
References:
No comments:
Post a Comment