Innovate anywhere, anytime withruncode.io Your cloud-based dev studio.
Amazon Web Services

How to Build and Verify an Application using AWS Codepipeline and Creating Custom Events with lambda

2022-07-19

Steps to deploy an application with AWS code pipeline:

  • Visit aws codepipeline console(https://console.aws.amazon.com/codepipeline/home)
  • Enter the pipeline name
  • Next, it’ll ask for source provider i.e your code locator for ex: Github, S3. Choose any of the option
  • In this blog post, we’re deploying it from the github, choose github. Click on connect to github
  • After connecting with GitHub, choose your application repository and branch, click on Next Step
  • Select Build Provider as AWS Code Build, choose any of the application in code builder, click on NEXT.
  • Choose deploy as No Deploy, because we’re not deploying the code.
  • Choose  AWS-CodePipeline-Service to give permissions for codepipeline
  • click on create a pipeline to create a pipeline.

Now It’ll run the test cases and verify it. Return success message if the test cases are passed otherwise returns failed message

We need to add an AWS Lambda service to create a custom event for sending notification emails if application status returns 200.

Steps to create a lambda service:

install boto -t . -- This will install the requirements with in the folder.
cd /mails/ zip -r -D mails.zip *
  • Create a folder with name mails and the new file(sending_email.py) in the folder
  • Install the required packages in the folder using pip
  • Write a script for sending the mail using aws ses service in sending_email.py.
  • Create a zip folder with the following command:
  • Go to aws Lambda console(https://console.aws.amazon.com/lambda/home)
  • Click on Create Function
  • Give function name, programming language details, a role for the function. It’ll create a new function
  • In the Function Code block, Choose entry type as Upload a .zip file, click on upload
  • After the save the function, test it.
  • It will return the response if required packages are installed, otherwise, it’ll return a detailed error message

Now we need to link aws lambda to the aws codepipeline. For that click on edit in the pipeline view page.

  • Click on add new stage && add new action
  • Choose action category as Invoke, Give a name to a particular action, choose lambda
  • Select AWS Lambda Function name, and the parameters if it is required, click on add action.
  • It’ll add to the codepipeline, run the script for every pipeline from now onwards.