{"id":185,"date":"2024-05-31T23:14:07","date_gmt":"2024-06-01T06:14:07","guid":{"rendered":"http:\/\/184.72.63.26\/?p=185"},"modified":"2024-06-17T23:19:22","modified_gmt":"2024-06-18T06:19:22","slug":"use-aws-codepipeline-ci-cd-to-automate-unit-test-and-deploy-lambda-function","status":"publish","type":"post","link":"https:\/\/www.wallacel.com\/index.php\/2024\/05\/31\/use-aws-codepipeline-ci-cd-to-automate-unit-test-and-deploy-lambda-function\/","title":{"rendered":"Use AWS CodePipeline CI\/CD to automate Unit Test and Deploy Lambda Function"},"content":{"rendered":"\n<p>In this guide, I will walk you through setting up a Continuous Integration and Continuous Deployment (CI\/CD) pipeline. This pipeline will automate unit testing and deploy your code to an AWS Lambda function using AWS CodePipeline, CodeBuild and CloudFormation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"450\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/cicd-pipeline-3.png\" alt=\"\" class=\"wp-image-203\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/cicd-pipeline-3.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/cicd-pipeline-3-300x176.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Source Stage<\/h2>\n\n\n\n<p>Our journey begins with a GitHub repository, which stores our source code. Any time changes are pushed to this repository, the pipeline is automatically triggered.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Build &amp; Test Stage<\/h2>\n\n\n\n<p>Next, AWS CodeBuild steps in to compile the source code and run unit tests. Upon successful completion, the build artifacts are stored in an S3 bucket.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deploy Stage<\/h2>\n\n\n\n<p>Finally, AWS CloudFormation takes over, retrieving the artifacts (source code) from the S3 bucket and deploying the function to AWS Lambda.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Create Lambda Function<\/h2>\n\n\n\n<p>As an example, I create a simple Lambda Function that takes a city name as a parameter and returns the current temperature. To fetch the weather information, I signup for a free account at <a href=\"https:\/\/openweathermap.org\/\" data-type=\"link\" data-id=\"https:\/\/openweathermap.org\/\">OpenWeather.org<\/a> to use their API. Following is the API call to get the weather data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">http:\/\/api.openweathermap.org\/data\/2.5\/weather?q=city_name&amp;appid=api_key&amp;units=metric<\/code><\/pre>\n\n\n\n<p>This is my Lambda function:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"669\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/lambda-func.png\" alt=\"\" class=\"wp-image-516\" style=\"width:787px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-func.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-func-300x196.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-func-768x502.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I use the following event data to test my function and get a response that shows the function is working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n  \"city\": \"Vancouver\"\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"367\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/lambda-test2.png\" alt=\"\" class=\"wp-image-517\" style=\"width:669px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-test2.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-test2-300x108.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/lambda-test2-768x275.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I create a GitHub repository and upload my code with following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">git add.; git commit -m \"Add Lambda Function Python code\"; git push<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create CodeBuild Project<\/h2>\n\n\n\n<p>Go to AWS CodeBuild console and click on Create project. To enable CodeBuild to retrieve source code from GitHub, setup a connection using OAuth and choose the source code repository. This connection allows CodeBuild to automatically fetch and build the source code whenever changes are pushed to the specified GitHub repository.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"738\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/source.png\" alt=\"\" class=\"wp-image-188\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/source.png 736w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/source-300x300.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/source-150x150.png 150w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/figure>\n\n\n\n<p>Since my Lambda function is written in Python and there is no Python runtime available in the standard environment options, I use a standard runtime and specify my runtime by using a buildspec file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"788\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/env1.png\" alt=\"\" class=\"wp-image-518\" style=\"width:675px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/env1.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/env1-300x231.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/env1-768x591.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/buildspec2.png\" alt=\"\" class=\"wp-image-519\" style=\"width:674px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/buildspec2.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/buildspec2-300x145.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/buildspec2-768x371.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The buildspec file ensures that CodeBuild uses the specified Python runtime to build and test my Lambda function code. This file is also where I add automated unit tests. Here\u2019s how I set up my <code>buildspec.yml<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">version: 0.2\nphases:\n  install:\n    runtime-versions:\n      python: 3.10   # Specify the Python version you need\n  build:\n    commands:\n      - echo Testing the Lambda functon...\n      - python -m unittest discover tests\nartifacts:\n  files:\n    - '**\/*'    # Include all files in the build output<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>install phase<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>runtime-versions<\/code> <em>specifies the Python version.<\/em><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>build phase<\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>python -m unittest discover test<\/code> &#8211; <em>a Python testing framework that supports test discovery by automatically discover and run all test methods with a project directory, in this case the &#8216;<strong>test<\/strong>&#8216; folder.<\/em><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>artifacts<\/strong>:\n<ul class=\"wp-block-list\">\n<li><em>Specifies which files to include in the build output.<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s a simple unit test example. It checks two things: whether the function returns a success code of 200, and whether the response includes the same city name I provided along with its current temperature:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">def unit_test(self):\n    event={'city':'Vancouver'}\n    result = lambda_function.lambda_handler(event, None)\n    self.assertEqual(result['statusCode'], 200)\n    self.assertEqual(result['headers']['Content-Type'], 'application\/json')\n    self.assertIn(event['city'], result['body'])\n    self.assertIn('current_temperature', result['body'])<\/code><\/pre>\n\n\n\n<p>CodeBuild saves the code as a zip file in S3 bucket, which is a crucial step. Later on, CloudFormation will use this stored code as a source to deploy it to Lambda.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"732\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/artifact2.png\" alt=\"\" class=\"wp-image-520\" style=\"width:496px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/artifact2.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/artifact2-300x214.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/artifact2-768x549.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can set up webhook events to tell CodeBuild to rebuild your code whenever there&#8217;s a push request on GitHub. However, I prefer to add this to my CodePipeline instead and have it trigger CodeBuild automatically.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"248\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/webhook.png\" alt=\"\" class=\"wp-image-521\" style=\"width:534px;height:auto\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/webhook.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/webhook-300x73.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/webhook-768x186.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Create CloudFormation Stack<\/h2>\n\n\n\n<p>To deploy my Python function code to AWS Lambda using CloudFormation, I need to prepare a CloudFormation template that specifies the location of the source code zip file stored in the S3 bucket. Here&#8217;s an example of how my <code>cloudformation_lambda.yml<\/code> template looks:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">Resources:\n  LambdaFunction:\n    Type: 'AWS::Lambda::Function'\n    Properties:\n      FunctionName: myWeatherLambda\n      Handler: index.handler\n      Runtime: python3.10\n      Role: !GetAtt LambdaFunctionRole.Arn\n      MemorySize: 1024\n      Code: \n        S3Bucket: wallace-bucket-for-codebuild\n        S3Key: myWeatherLambdaCodeBuild\/codebuild.zip\n                  \n  LambdaFunctionRole:\n    Type: AWS::IAM::Role\n    Properties:\n      AssumeRolePolicyDocument:\n        Version: '2012-10-17'\n        Statement:\n        - Effect: Allow\n          Principal:\n            Service:\n            - lambda.amazonaws.com\n          Action:\n          - sts:AssumeRole\n      Path: \"\/\"\n      Policies:\n      - PolicyName: AppendToLogsPolicy\n        PolicyDocument:\n          Version: '2012-10-17'\n          Statement:\n          - Effect: Allow\n            Action:\n            - logs:CreateLogGroup\n            - logs:CreateLogStream\n            - logs:PutLogEvents\n            Resource: \"*\"<\/code><\/pre>\n\n\n\n<p>The &#8216;<strong>S3Bucket<\/strong> &#8216; parameter specifies the S3 bucket name and the &#8216;<strong>S3Key<\/strong>&#8216; parameter indicates where the Lambda function code zip file is stored. The template also creates a Lambda function role that grants the Lambda function permission to write logs.<\/p>\n\n\n\n<p>Go to CloudFormation console and click on Create stack. I use the <code>cloudformation_lambda.yml<\/code> template I prepared to create a stack:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"860\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/stack2.png\" alt=\"\" class=\"wp-image-522\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/stack2.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/stack2-300x252.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/stack2-768x645.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Stage 4: Create Service role for CodePipeline<\/h2>\n\n\n\n<p>A service role is needed to grant permission to CodePipeline to access the S3 bucket, deploy CloudFormation stacks, create Lambda function role and other necessary actions. Here&#8217;s how to create the IAM role, go to IAM console and click on Roles and Create role.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"707\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/trust.png\" alt=\"\" class=\"wp-image-523\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trust.png 767w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trust-300x277.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/figure>\n\n\n\n<p>Edit the trust relationships to change the service from &#8216;<strong>ec2.amazonaws.com<\/strong>&#8216; to &#8216;<strong>cloudformation.amazonaws.com<\/strong>&#8216;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"349\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/trust2.png\" alt=\"\" class=\"wp-image-524\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trust2.png 800w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trust2-300x131.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trust2-768x335.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>Create an inline policy to grant permission to the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>S3<\/strong>: Allows GetObject, PutObject, and related actions for all buckets.<\/li>\n\n\n\n<li><strong>IAM<\/strong>: Permissions for role management, including creation, deletion, and policy attachment.<\/li>\n\n\n\n<li><strong>Lambda:<\/strong> Allows invoking Lambda functions and listing available Lambda functions, creation, deletion and updates.<\/li>\n\n\n\n<li><strong>CloudFormation: <\/strong>Allows managing CloudFormation stacks, such as <code>CreateStack<\/code>, <code>DeleteStack<\/code>, etc.<\/li>\n\n\n\n<li><strong>CodeBuild<\/strong>: Allows BatchGetBuilds and StartBuild actions for CodeBuild projects.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n\t\"Statement\": [\n\t\t{\n\t\t\t\"Action\": [\n\t\t\t\t\"s3:GetObject\",\n\t\t\t\t\"s3:GetObjectVersion\",\n\t\t\t\t\"s3:GetBucketVersioning\",\n\t\t\t\t\"s3:PutObject\"\n\t\t\t],\n\t\t\t\"Resource\": [\n\t\t\t\t\"arn:aws:s3:::*\"\n\t\t\t],\n\t\t\t\"Effect\": \"Allow\"\n\t\t},\n\t\t{\n\t\t\t\"Action\": [\n\t\t\t\t\"iam:CreateRole\",\n\t\t\t\t\"iam:DeleteRolePolicy\",\n\t\t\t\t\"iam:GetRole\",\n\t\t\t\t\"iam:GetRolePolicy\",\n\t\t\t\t\"iam:PassRole\",\n\t\t\t\t\"iam:DetachRolePolicy\",\n\t\t\t\t\"iam:DeleteRolePolicy\",\n\t\t\t\t\"iam:DeleteRole\",\n\t\t\t\t\"iam:AttachRolePolicy\",\n\t\t\t\t\"iam:PutRolePolicy\",\n\t\t\t\t\"iam:PassRole\"\n\t\t\t],\n\t\t\t\"Resource\": [\n\t\t\t\t\"arn:aws:iam::*:role\/*\"\n\t\t\t],\n\t\t\t\"Effect\": \"Allow\"\n\t\t},\n\t\t{\n\t\t\t\"Action\": [\n\t\t\t\t\"lambda:GetFunction\",\n\t\t\t\t\"lambda:GetFunctionConfiguration\",\n\t\t\t\t\"lambda:CreateFunction\",\n\t\t\t\t\"lambda:DeleteFunction\",\n\t\t\t\t\"lambda:InvokeFunction\",\n\t\t\t\t\"lambda:ListFunctions\"\n\t\t\t],\n\t\t\t\"Resource\": [\n\t\t\t\t\"arn:aws:lambda:ca-central-1:339713082608:function*\"\n\t\t\t],\n\t\t\t\"Effect\": \"Allow\"\n\t\t},\n\t\t{\n\t\t\t\"Action\": [\n\t\t\t\t\"cloudformation:CreateStack\",\n\t\t\t\t\"cloudformation:DeleteStack\",\n\t\t\t\t\"cloudformation:DescribeStacks\",\n\t\t\t\t\"cloudformation:UpdateStack\",\n\t\t\t\t\"cloudformation:CreateChangeSet\",\n\t\t\t\t\"cloudformation:DeleteChangeSet\",\n\t\t\t\t\"cloudformation:DescribeChangeSet\",\n\t\t\t\t\"cloudformation:ExecuteChangeSet\",\n\t\t\t\t\"cloudformation:SetStackPolicy\",\n\t\t\t\t\"cloudformation:ValidateTemplate\"\n\t\t\t],\n\t\t\t\"Resource\": [\n\t\t\t\t\"arn:aws:cloudformation:ca-central-1:339713082608:stack*\"\n\t\t\t],\n\t\t\t\"Effect\": \"Allow\"\n\t\t},\n\t\t{\n\t\t\t\"Action\": [\n\t\t\t\t\"codebuild:BatchGetBuilds\",\n\t\t\t\t\"codebuild:StartBuild\"\n\t\t\t],\n\t\t\t\"Resource\": \"arn:aws:codebuild:ca-central-1:339713082608:project*\",\n\t\t\t\"Effect\": \"Allow\"\n\t\t}\n\t],\n\t\"Version\": \"2012-10-17\"\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Stage 5: Create CodePipeline<\/h2>\n\n\n\n<p>Now, the final step is to integrate all the components by creating a CodePipeline. Here\u2019s how to set it up: <\/p>\n\n\n\n<p>Go to CodePipeline console and click on Create pipeline. Set the source provider to GitHub and specify the repository that contains the source code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"850\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/source-2.png\" alt=\"\" class=\"wp-image-208\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/source-2.png 730w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/source-2-258x300.png 258w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/figure>\n\n\n\n<p>A git push to the repository will trigger the pipeline:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"747\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/trigger.png\" alt=\"\" class=\"wp-image-525\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trigger.png 729w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/trigger-293x300.png 293w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/figure>\n\n\n\n<p>To configure the build stage, use AWS CodeBuild as the build provider with the CodeBuild project created in Step 2.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"620\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/05\/build.png\" alt=\"\" class=\"wp-image-205\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/build.png 734w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/05\/build-300x253.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/figure>\n\n\n\n<p>Use AWS CloudFormation as the deploy provider and specify the CloudFormation template prepared in Step 3 in the File name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"487\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/deploy2.png\" alt=\"\" class=\"wp-image-526\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/deploy2.png 728w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/deploy2-300x201.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/figure>\n\n\n\n<p>For role name, use the IAM service role created in Step 4.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"171\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/iam.png\" alt=\"\" class=\"wp-image-527\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/iam.png 729w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/iam-300x70.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/figure>\n\n\n\n<p>With the CodePipeline set up, push a change to the GitHub repository to see the pipeline in action.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"1024\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/codepipeline.png\" alt=\"\" class=\"wp-image-528\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/codepipeline.png 699w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/codepipeline-205x300.png 205w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"974\" height=\"642\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/action-exec.png\" alt=\"\" class=\"wp-image-529\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/action-exec.png 974w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/action-exec-300x198.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/action-exec-768x506.png 768w\" sizes=\"auto, (max-width: 974px) 100vw, 974px\" \/><\/figure>\n\n\n\n<p>Once the pipeline executes, go to the Lambda console to verify if the Lambda function has been created successfully.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"514\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/weather-lambda.png\" alt=\"\" class=\"wp-image-530\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/weather-lambda.png 1001w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/weather-lambda-300x154.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/weather-lambda-768x394.png 768w\" sizes=\"auto, (max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<p>Thank you for reading! You can find my GitHub repo <a href=\"https:\/\/github.com\/wallylee99\/automated_testing_pipeline\">here<\/a>. I hope this guide gives you a clear understanding of how to set up a CI\/CD pipeline with AWS CodePipeline. Stay tuned for more exciting AWS guides and insights.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, I will walk you through setting up a Continuous Integration and Continuous Deployment (CI\/CD) pipeline. This pipeline will automate unit testing and deploy your code to an AWS Lambda function using AWS CodePipeline, CodeBuild and CloudFormation. Source Stage Our journey begins with a GitHub repository, which stores our source code. Any time [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":229,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[19,24,25],"class_list":["post-185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","tag-aws","tag-ci-cd","tag-pipeline"],"_links":{"self":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/comments?post=185"}],"version-history":[{"count":18,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions"}],"predecessor-version":[{"id":531,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/185\/revisions\/531"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media\/229"}],"wp:attachment":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media?parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/categories?post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/tags?post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}