简体   繁体   中英

How to deploy a WAR file from s3 to AWS EC2?

I have a AWS EC2 instance running with me and there is a maven project running on tomcat7. What I have tried is I am using Jenkins for the CI.So whenever the new push happens to the Git-hub Jenkins starts to build, after completion of build it will upload the war file to the AWS S3. Where I have stuck is, I am not getting a way to deploy the war file to the AWS Ec2 instance.

I have tried to use Code Deployment where at a point it showed me that it supports only tar, tar.gz and zip is there any way out to deploy the war file to the AWS EC2 instance from the S3.

Thank you.

You can use Amazon Code Deploy which can manage deployment from a S3 bucket and can automate deployment to EC2 instance of your file/scripts.

From the Overview of a Deployment

Here's how it works:

  1. First, you create deployable content – such as web pages, executable files, setup scripts, and so on – on your local development machine or similar environment, and then you add an application specification file (AppSpec file). The AppSpec file is unique to AWS CodeDeploy; it defines the deployment actions you want AWS CodeDeploy to execute. You bundle your deployable content and the AppSpec file into an archive file, and then upload it to an Amazon S3 bucket or a GitHub repository. This archive file is called an application revision (or simply a revision).
  2. Next, you provide AWS CodeDeploy with information about your deployment, such as which Amazon S3 bucket or GitHub repository to pull the revision from and which set of instances to deploy its contents to. AWS CodeDeploy calls a set of instances a deployment group. A deployment group contains individually tagged instances, Amazon EC2 instances in Auto Scaling groups, or both.
    Each time you successfully upload a new application revision that you want to deploy to the deployment group, that bundle is set as the target revision for the deployment group. In other words, the application revision that is currently targeted for deployment is the target revision. This is also the revision that will be pulled for automatic deployments.
  3. Next, the AWS CodeDeploy agent on each instance polls AWS CodeDeploy to determine what and when to pull the revision from the specified Amazon S3 bucket or GitHub repository.
  4. Finally, the AWS CodeDeploy agent on each instance pulls the target revision from the specified Amazon S3 bucket or GitHub repository and, using the instructions in the AppSpec file, deploys the contents to the instance.

AWS CodeDeploy keeps a record of your deployments so that you can get information such as deployment status, deployment configuration parameters, instance health, and so on.

Good part is that code deploy has no additional cost, you only pay for the resources (EC2, S3) that are used in your pipeline

Assuming you have already created a S3 bucket.

Step 1: Create a IAM user / Role who have access to a s3 bucket where in you are placing the WAR file

Step 2: Write a custom script which will download WAR File from S3 to your EC2 instance.

You can also use aws cli to download contents from s3 to your local machine.

Create a startup.sh file and add these contents

aws s3 cp s3://com.yoursitename/warFile/sample.war /tmp
sudo mv /tmp/sample.war /var/lib/tomcat/webapps/ROOT.war
sudo service tomcat restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM