Setup Github actions to build and deploy java code on EC2 - amazon-ec2

I have been trying to make Github actions to setup CI/CD for aws ec2 machine. I tried working with aws actions i.e. https://github.com/aws-actions but it only talks about deploying to ECS or by using Codebuild.
Is it possible to do this with Github actions alone? Steps which I am trying to do are:
1) build with maven
2) Deploy to ec2
I am new to this so any pointers would be helful.

Related

How to migrate from certificate-based Kubernetes integration to the Gitlab agent for Kubernetes

I have some integration tubes for more than a year working without any problem. And I realize that until this month February 2023 support for the integration of certified-based Kubernetes ends. So I have to migrate to using something called Gitlab agent. Which apparently exists a few days ago and I had not noticed. I have created the agent without problems in my Kubernetes cluster following the gitlab documentation, but I have a small problem.
How can I tell my CI/CD workflow to stop using my old certificate-based integration and now start using my new Gitlab agent to authenticate/authorize/integrate with my kubernetes cluster.
I have followed these instructions https://docs.gitlab.com/ee/user/infrastructure/clusters/migrate_to_gitlab_agent.html
But the part I'm not quite clear on is what additional instructions I should add to my .gitlab-ci.yml file to tell it to use the gitlab agent.
I already created gitlab agent, created config.yaml, also gitlab says that they are connected with my GKE.
Try adding a tag in my config.yaml like this.
ci_access:
projects:
-id: path/to/project
In the same way, the integration pipeline worked without problems, but I am sure that it is working because it is connected in the other way. Any way to ensure that it is working with the gitlab agent?

CI/CD involves EC2

Our code is divided to modules and stored on local Git server. The various modules are built and uploaded to the ECR.
Question: currently, can execute deployment on certain EC2 instance. What will be the preferred for my local Jenkins server to run the Deploy actions on the EC2?
Note: I've finished Working with SSM in the past with BAD impression!!
Thx - Albert

Migrate Spring Boot project from Amazon Linux 1 to Amazon Linux 2

I have a Spring Boot project that is running on an EC2 instance via Elastic Beanstalk. This project was created by AWS CodeStar and they also provided an out-of-the-box project template. You can see the template here: https://github.com/JanHorcicka/AWS-Codestar-Spring-Webapp-EBS-Template
The problem is that this project is automatically deployed to an EC2 instance running Amazon Linux 1. To project template is built to work on AL1. Unfortunately, some tools I want to install (Certbot) require Amazon Linux 2. There are ways to switch from AL1 to AL2. For example here: Create Amazon Linux 2 instance via CodeStar
The problem is that after I switch to AL2, the provided project template doesn't work.
I know there are some differences for Elastic Beanstalk for different version of AL. For example I read somewhere, that the AL2 is not using .ebextensions folder anymore. But I cannot find the full list of changes.
How do I have to modify the template to make it work also on AL2 instance?

How do developers typically use Docker with a Java Maven project and AWS EC2?

I have a single Java application. We developed the application in Eclipse. It is a Maven project. We already have a system for launching our application to AWS EC2. It works but is rudimentary and we would like to learn about the more common and modern approaches other teams use to launch their Java Maven apps to EC2. We have heard of Docker and I researched the tool yesterday. I understand the basics of building an image, tagging it and pushing to either Docker Hub or Amazon's ECS service. I have also read through a few tutorials describing how to pull a Docker image into an EC2 instance. However, I don't know if this is what we are trying to do, given that I am a bit confused about the role Docker can play in our situation to help make our dev ops more robust and efficient.
Currently, we are building our Maven app in Eclipse. When the build completes, we run a second Java file that uses the AWS JDK for Java to
launch an EC2 instance
copy the.jar artifact from the build into this instance
add the instance to a load balancer and
test the app
My understanding of how we can use Docker is as follows. We would Dockerize our application and push it to an online repository according to the steps in this video.
Then we would create an EC2 instance and pull the Docker image into this new instance according to the steps in this tutorial.
If this is the typical flow, then what is the purpose of using Docker here? What is the added benefit, when we are currently ...
creating the instance,
deploying the app directly to the instance and also
testing the running app
all using a simple single Java file and functions from the AWS SDK for Java?
#GNG what are your objectives for containerization?
Amazon ECS is the best method if you want to operate in only AWS environment.
Docker is effective in hybrid environments i.e., on physical servers and VMs.
the Docker image is portable and complete executable of your application: it delivers your jar, but it can also include property files, static resources, etc... You package everything you need and deploy to AWS, but you could decide also to deploy the same image on other platforms (or locally).
Another benefit is the image contains the whole runtime (OS, jdk) so you dont rely on what AWS provides ensuring also isolation from the underlying infrastructure.

Aws Lambda Deployment via CodePipeline

I would like to deploy my Lambda methods by using Aws Codepipeline. However, when i follow Aws Codepipeline creation wizard, i couldn't understand which one should i choose at beta stage. Because, not only Aws Codedeploy, but also Elastic Beanstalk are concerning only EC2 instances. There is lack of tutorial about telling step by step to create pipeline for our lambda, apigateway deployments. How can i skip beta stage without choosing one of them?, or which one should i choose for my serverless architecture's deployments?.
There are no direct integrations for Lambda/API Gateway -> CodePipeline at the moment. You could certainly do something with Jenkins like #arjabbar suggested. Thanks for the feedback, we'll take this on our backlog.
CloudFormation is available in CodePipeline now. This allows you to target cloudformation templates as Actions in the CodePipeline.
Here's an overview (the implementation was moved to a private repository after I changed positions):
https://aws.amazon.com/blogs/compute/continuous-deployment-for-serverless-applications/
In this pipeline we deploy a staging lambda, test its functionality, then deploy the production lambda.

Resources