Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 132 additions & 45 deletions MF06-PRA06.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This practical exercise will guide you through setting up an AWS environment to
2. Follow the registration process, providing necessary information
3. Choose a support plan (Basic is free and sufficient for this exercise)

![](PRA06_ANSWER/screenshots/1-create-an-aws-account.png)

#### 2. Set Up AWS Budget and Billing Alerts

1. Navigate to AWS Budgets in the AWS Management Console
Expand All @@ -20,6 +22,20 @@ This practical exercise will guide you through setting up an AWS environment to
4. Configure alerts for 80% of your budgeted amount[5]
5. Set up an action to automatically apply an IAM policy restricting resource creation when the budget is exceeded[3]

![](PRA06_ANSWER/screenshots/2-1-set-up-aws-budget-and-billing-alerts.png)


Having problems during the budget creation:
![](PRA06_ANSWER/screenshots/2-2-problems-creation-budget.png)


Solved by creating a role who has full access to AWS Budget Actions:
![](PRA06_ANSWER/screenshots/2-3-creation-role-with-budget-permssion.png)


The budget has been created successfully:
![](PRA06_ANSWER/screenshots/2-4-budget-created.png)

#### 3. Create AWS Services for Spring Boot Docker Deployment

##### Set up Amazon Elastic Container Registry (ECR)
Expand All @@ -29,43 +45,102 @@ This practical exercise will guide you through setting up an AWS environment to
3. Name your repository (e.g., "spring-boot-app")
4. Configure repository settings and create

![](PRA06_ANSWER/screenshots/3-1-elastic-container-registry.png)

##### Configure Amazon Elastic Container Service (ECS)

1. Open the Amazon ECS console
2. Click "Create Cluster"
3. Choose "Networking only" for Fargate compatibility
4. Name your cluster and create

![](PRA06_ANSWER/screenshots/3-2-cluster-creation.png)

##### Set up AWS Fargate

1. In the ECS console, create a new task definition
2. Choose Fargate as the launch type
3. Configure task size (CPU and memory)
4. Add container details using the ECR image

New task definition:
![](PRA06_ANSWER/screenshots/3-3-task-definition.png)

Container creation:
![](PRA06_ANSWER/screenshots/3-4-container-creation.png)

Service creation:
- Enviroment
![](PRA06_ANSWER/screenshots/3-5-1-service-creation-enviroment.png)

- Deployment
![](PRA06_ANSWER/screenshots/3-5-2-service-creation-deployment-configuration.png)

- Networking
![](PRA06_ANSWER/screenshots/3-5-3-service-creation-networking.png)

- Load Balancing
![](PRA06_ANSWER/screenshots/3-5-4-service-creation-load-balancing-1.png)
![](PRA06_ANSWER/screenshots/3-5-4-service-creation-load-balancing-2.png)




#### 4. Update Jenkins Pipeline for AWS Deployment

Modify your Jenkins pipeline to include AWS deployment steps:
Modified Jenkins pipeline to include AWS deployment steps:

```groovy
pipeline {
agent any

environment {
AWS_ACCOUNT_ID="your-account-id"
AWS_DEFAULT_REGION="your-region"
IMAGE_REPO_NAME="spring-boot-app"
AWS_ACCOUNT_ID="954976290202"
AWS_DEFAULT_REGION="eu-central-1"
IMAGE_REPO_NAME="books/booksback"
IMAGE_TAG="${env.BUILD_ID}"
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
IMAGE_NAME = 'books/booksback'
}


tools {
maven 'M3'
jdk 'JDK21'
}

stages {
// Previous stages (build, test) here
stage('Checkout') {
steps {
git 'https://github.com/AlbertProfe/BooksPageable.git'
}
}

stage('Build') {
steps {
sh 'mvn clean package'
}
}

stage('Archive') {
steps {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}

stage('Build Docker Image') {
steps {
script {
// Build the Docker image and tag it with both BUILD_NUMBER and latest
sh "docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -t ${IMAGE_NAME}:latest ."
}
}
}

stage('Push to ECR') {
steps {
script {
sh "aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
sh "aws ecr-public get-login-password --region eu-central-1 | docker login --username AWS --password-stdin public.ecr.aws/c3d9t1n8"
sh "docker tag ${IMAGE_REPO_NAME}:${IMAGE_TAG} ${REPOSITORY_URI}:${IMAGE_TAG}"
sh "docker push ${REPOSITORY_URI}:${IMAGE_TAG}"
}
Expand All @@ -75,49 +150,61 @@ pipeline {
stage('Deploy to ECS') {
steps {
script {
sh "aws ecs update-service --cluster your-cluster-name --service your-service-name --force-new-deployment"
sh "aws ecs update-service --cluster booksback --booksbackSpringService --force-new-deployment"
}
}
}
}
}

post {
always {
// Logout from DockerHub and remove images
sh "docker logout"
sh "docker rmi ${IMAGE_NAME}:${IMAGE_TAG} || true"
sh "docker rmi ${IMAGE_NAME}:latest || true"
}
}
}
```

#### 5. Deploy Spring Boot Application

1. Run the Jenkins pipeline to build and push the Docker image to ECR
2. The pipeline will trigger a new deployment in ECS using Fargate

### Additional Notes

- Ensure proper IAM roles and permissions are set for Jenkins to interact with AWS services
- Configure network settings in ECS task definition for your Spring Boot application
- Set up an Application Load Balancer if needed for routing traffic to your Fargate tasks

### Submission Guidelines

- Fork the repository or create a new one on GitHub
- Create a branch named `MF06-PRA06-YourNameAndSurname`
- Implement the required changes and add necessary configuration files
- Commit with clear messages
- Push your branch and create a pull request titled `MF06-PRA06-YourNameAndSurname-AWSDeployment`
- Create a `PRA06_ANSWER` folder to save the answer, docs, and images

### Evaluation Criteria

- Successful creation and configuration of AWS account with proper budget controls
- Correct setup of ECR, ECS, and Fargate services
- Proper modification of Jenkins pipeline for AWS deployment
- Successful deployment of Spring Boot application to AWS
- Clear documentation and commit messages

Citations:
[1] https://repost.aws/es/questions/QU3DjdqNvwSnW1maqrMxseuw/how-to-add-a-total-monthly-spend-limit-in-2023
[2] https://docs.aws.amazon.com/cost-management/latest/userguide/management-limits.html
[3] https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-controls.html
[4] https://www.youtube.com/watch?v=SX6LoXTmpdM
[5] https://aws.amazon.com/getting-started/hands-on/control-your-costs-free-tier-budgets/
[6] https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html?icmpid=docs_costmanagement_hp-choose-type
[7] https://www.youtube.com/watch?v=zt6Dur9fVGk
[8] https://www.reddit.com/r/aws/comments/l362qg/is_there_a_tool_for_limiting_aws_spending/
[9] https://curc.readthedocs.io/en/latest/cloud/aws/lca1/billing/budget-actions.html
1.Access key creation:
![](PRA06_ANSWER/screenshots/5-1-access-key.png)


2.Errors and Changes

Error 1:
![](PRA06_ANSWER/screenshots/5-4-error-1.png)

Change:
![](PRA06_ANSWER/screenshots/5-4-change-1.png)


Error 2:
![](PRA06_ANSWER/screenshots/5-4-error-2.png)

Change:
![](PRA06_ANSWER/screenshots/5-4-change-2.png)


Error 3:
![](PRA06_ANSWER/screenshots/5-4-error-3.png)

Changes:
![](PRA06_ANSWER/screenshots/5-4-change-3.1.png)

![](PRA06_ANSWER/screenshots/5-4-change-3.2.png)


Error 4:
![](PRA06_ANSWER/screenshots/5-4-error-4.png)

Change:
![](PRA06_ANSWER/screenshots/5-4-change-4.png)




I could not find a solution yet.
Loading