Use the following repo to deploy your infrastructure on AWS.
Repo: https://github.com/DevOpsTestLab/infra
This repo has the terraform templates required to deploy the following resources:
- AWS Codepipeline - your CICD orchestrator
- AWS CodeCommit - Your source code repo
- AWS ECR - Your container registry
- Use terraform from your local to deploy these resources on AWS
- Use the AWS CLI to configure your user/roles/policy needed to deploy these resources
- Store the statefile for this on a S3 bucket if possible. However its fine if you store it locally
- Review the var files to ensure that all the right variables are available for the templates to execute successfully
- Review the modules for each of the resources under the mdoules folder - https://github.com/DevOpsTestLab/infra/tree/main/modules
Once you successfully complete the above step, you will have a codecommit repository created. Go ahead and download and upload the following application codebase into your new CodeCommit Repo
Application Codebase - https://github.com/DevOpsTestLab/sample-aws-lambda
This is a simple hello-world application built on python. Which gets packaged as a Docker Container and Deploy to AWS Lambda.
- Review the application code here - https://github.com/DevOpsTestLab/sample-aws-lambda/blob/main/lambda/aws-lambda-url.py (This just prints hello)
- Review the dockerfile here - https://github.com/DevOpsTestLab/sample-aws-lambda/blob/main/lambda/Dockerfile
- This application is also deployed to AWS using Terraform. Here is the terraform template, https://github.com/DevOpsTestLab/sample-aws-lambda/blob/main/main.tf
Once you commit your code into AWS CodeCommit. The pipeline created from Task 1 will be kicked off automatically. Make sure the build stage is successfully.
The build stage is driven by this codebuild step and this buildspec file
Update the buildspec file if you need to and re-apply the terraform templates to update your infrastructure
The next step is the sonarqube quality scan step. Its driven by the following buildspec file
We will be using sonarcloud which is the SaaS offering for Sonarqube analysis - https://sonarcloud.io/
Have the following SSM Parameters created manually or though terraform from step 1 that is needed by your sonarqube analysis step.
Use the corresponding values for your
- token - https://sonarcloud.io/account/security
- organization - https://sonarcloud.io/account/organizations
- sonarendpoint will be - https://sonarcloud.io/
Some documentation for your reference - https://docs.sonarcloud.io/advanced-setup/analysis-parameters/
Update the buildspec file if you need to and re-apply the terraform templates to update your infrastructure
The next step is the sonarqube quality scan step. Its driven by the following buildspec file
Update the buildspec file if you need to and re-apply the terraform templates to update your infrastructure
Once the Lambda fuction is deploy. Run a test with some test event. The results should just print "hello world"
NOTE:
- Keep in mind that you may run into issues due to any errors deliberately injected into the terraform templates/buildspec files.
- Dont expect things to work out of the box. Make the necessary assumptions when you get blocked.
- Remember that you may be questioned on your troubleshooting/problem solving capabilities as well