AWS: execute script when deploying Application? - amazon-web-services

I would like to use EB CLI to deploy my PHP Application to AWS ElasticBeanstalk but I am wondering if there is a way to execute additional commands, for example download dependencies and compile files, etc.
Do I need to create a script? If yes how can I do it?
Any documentation is very appreciated.
Thank you

In general, the idea of beanstalk is that you do all the downloading of dependencies etc yourself (ideally in a CI pipeline), create a deployable package and then hand it over to beanstalk for deployment and execution.
You may want to look into AWS CodePipeline for running scripts, building and packaging before deploying to beanstalk.

Related

How to build with jenkins and deploy on aws?

I have the following task. I have a spring-boot app(backend), and a react app(frontend). I want to build the apps and deploy them on aws. I want to build them with Jenkins. What is the right way to do it? Should Jenkins be on a separate instance and deploy the apps on other instances? Should I use ECS? Using ECS with Jenkins seems like a complex task. The information online is confusing. If you have some guides that would be great.
if you want to deploy to AWS : the easiest way to get started is to use aws developer tools
code commit - to store your source code. it is based on git
code build - to build and test your code.
code depoy - to deploy on ec2 instances or ECS, whatever you like
Code pipeline - to connect 1, 2 and 3 and it also allows you to choose Jenkins in place of code build.
https://aws.amazon.com/products/developer-tools/

How to upload application code to AWS Beanstalk

I have a pre-built jar that I can deploy on an ec2-instance and it runs reading from a queue and processing some business logic. I want to use it with AWS Beanstalk but when I try to do that Beanstalk asks for application source code in a zip format. Does this mean that I have to provide the code of just my application? but there are a lot of jars that my application jar depends on and does this mean I must package the source code of those jars also with my application jar? Anyway I can just upload my application compiled jar
There are two options for deployment to beanstalk.
you create a zip file of your application and upload it via the console
you use the eb-cli (from the command line) to create the zip file and do the deployment
Here is the documentation for java applications: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Java.html
And the documentation for the eb-cli:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html
After setting up the cli environment (getting ssh keys etc) you can deploy with eb deploy
About uploading code to AWS Beanstalk it can be done through beanstalk console.
Having lot of jar file for application, you need to combine all the files in single source bundle and then need to upload.
Below link gives example of
Bundling Multiple WAR Files for Tomcat Environments

AWS code deploy to deploy

Right now I am manually deploying WAR files onto wildfly server(which is hosted on an ec2 instance) but I want to automate this and get rid of the manual deployments.
I build the application using jenkins (from another EC2 instance) and after that i want to deploy to the wildfly server and since i am also planning to user codepipeline, can anyone please tell me how to deploy an applcation on wildfly server using AWS CodeDeploy?
I am new to codedeploy so not that familiar with its usage.
Thank you,
Ajit
Hi #Ajith Code Deploy is the perfect tool for deploying applications in AWS. But it has some limitations, for example to give a source repository for the Code Build/ Code Deploy you can only choose these 3 as the code repository.
AWS Code Commit
AWS S3 Bucket
Guthub
You cant provide your own custom repository or Bitbucket. Please go through the below Examples for deploying applications using Code Deploy. I can't explain all the steps because it have a lot of steps. here they are explaining app deployment using tomcat, replace this with your wildfly scripts.
Deploy Applications From S3 using Code Deploy.

Rerun elastic beanstalk ebextensions script from aws cli

I currently have an elastic beanstalk application using ebextensions.
It works great when the application is deployed for the first time but I want to be able to run the ebextension scripts again without redeploying.
I attempted to re-run the ebextension scripts from the aws cli.
Neither
aws elasticbeanstalk restart-app-server
aws elasticbeanstalk update-environment
seem to re-run the ebextensions scripts.
The files under .ebextensions are not retained after the deployment, so you'll need to redeploy to run them again. That being said, if you need the functionality outside of the deployment activity, you might want to implement it in another way.

Automate code deploy from Git lab to AWS EC2 instance

We're building an application for which we are using GitLab repository. Manual deployment of code to the test server which is Amazon AWS EC2 instance is tedious, I'm planning to automate deployment process, such that when we commit code, it should reflect in the test instance.
from my knowledge we can use AWS code-deploy service to fetch the code from GitHub. But code deploy service does not support GitLab repository . Is there a way to automate the code deployment process to AWS Ec2 instance through GitLab. or Is there a shell scripting possibility to achieve this? Kindly educate me.
One way you could achieve this with AWS CodeDeploy is by using the S3 option in conjunction with Gitlab-CI: http://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-w.html
Depending on how your project is setup, you may have the possibility to generate a distribution Zip (Gradle offers this through the application plugin). You may need to generate your "distribution" file manually if your project does not offer such a capability.
Gitlab does not offer a direct S3 integration, however through the gitlab-ci.yml you would be able to download it into the container and run the necessary upload commands to put the generated zip file on the S3 container as per the AWS instructions to trigger the deployment.
Here is an example of what your brefore-script could look like in the gitlab-ci.yml file:
before_script:
- apt-get update --quiet --yes
- apt-get --quiet install --yes python
- pip install -U pip
- pip install awscli
The AWS tutorial on how to use CodeDeploy with S3 is very detailed, so I will skip attempting to reproduce the contents here.
In regards to the actual deployment commands and actions that you are currently performing manually, AWS CodeDeploy provides the capability to run certain actions through scripts defined in the app-spec file depending on event hooks for the application:
http://docs.aws.amazon.com/codedeploy/latest/userguide/writing-app-spec.html
http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-hooks.html
I hope this helps.
This is one of my old post. But I happened to find an answer for this. Although my question is specific to work with code deploy I would say there is no such need to use any aws requirements using gitlab.
We don't require Code Deploy at all. There is no need to use any external CI server like the team city or the jenkins to perform the CI from the GitLab anymore.
We need to add the .gitlab-ci.yml file in the source directory of the branch and write an .yml script in it. There are pipelines in the GitLab that will perform the CI/CD automatically.
The pipelines of the GitLab CI/CD looks more similar to the working functionality of Jenkins Server. using the YML script we can perform SSH on the EC2 instance and place the files in it.
An example of how to write the gitlab .yml file to ssh to ec2 instance is here https://docs.gitlab.com/ee/ci/yaml/README.html