<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shailendra on Medium]]></title>
        <description><![CDATA[Stories by Shailendra on Medium]]></description>
        <link>https://medium.com/@shpals?source=rss-2d4fa12ecb1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wcBIkRj94LCm98ZHkDFSng.jpeg</url>
            <title>Stories by Shailendra on Medium</title>
            <link>https://medium.com/@shpals?source=rss-2d4fa12ecb1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 22:44:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shpals/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create AWS Lambda from ECR Docker image and integrate it with GitHub CI/CD pipeline.]]></title>
            <link>https://shpals.medium.com/create-aws-lambda-from-ecr-docker-image-and-integrate-it-with-github-ci-cd-pipeline-dfa3015b5ee0?source=rss-2d4fa12ecb1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfa3015b5ee0</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-ecr]]></category>
            <dc:creator><![CDATA[Shailendra]]></dc:creator>
            <pubDate>Mon, 01 Feb 2021 07:09:24 GMT</pubDate>
            <atom:updated>2021-02-03T04:17:27.996Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will explain how to create AWS Lambda from docker images in ECR (Elastic Container Registry) and integrate it with GitHub CI/CD pipeline. Creating a Lambda from docker image is a new feature released by AWS in December 2020.</p><p>To begin with, let&#39;s create a docker image repository in ECR.</p><ol><li>Go to ECR in AWS console and click on create repository.</li><li>Provide repository name and click create. Leave other settings as defaults.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*hGXM37c_L8ESr5X-bt0SPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bADCpxl5qnVHAlUZlut5mQ.png" /></figure><p>Before we start creating docker images of our code, we need to create a user with permission to push the image in ECR and update the Lambda function.</p><ol><li>Go to IAM, click Add user.</li><li>Provide user name, check Programmatic access and click permissions.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*jXsBPpfy1ZGoevSdBV0-uw.png" /></figure><p>3. On the next tab, select “Add user to group” and click create group.</p><p>4. Provide a group name and search for policies — “<a href="https://console.aws.amazon.com/iam/home?region=us-east-2#policies/arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess">AmazonEC2ContainerRegistryFullAccess</a>” , <a href="https://console.aws.amazon.com/iam/home?region=us-east-2#policies/arn:aws:iam::aws:policy/CloudWatchEventsReadOnlyAccess">CloudWatchEventsReadOnlyAccess</a>. Attach these policies to the group.</p><p>5. Create a new policy to update Lambda. The new policy json would have the following data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*BnPhGLG7yrE1dWA3IPxkDQ.png" /></figure><p>6. Attach the above policy to the group created in step 4.</p><p>7. Complete the create user wizard and note down the Access key ID and Secret.</p><p>8. Go to GitHub code repository → Settings → Secrets and provide the Access key ID and secret for the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRPvdXkg3QCpgHbfdR8IIA.png" /></figure><p>Now, let&#39;s add a GitHub Action to create a docker image from the source code and push it to the repository created in ECR.</p><ol><li>Go to the Actions tab in the GitHub code repository. Click new workflow and select “Deploy to Amazon ECS” action and click setup this workflow.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-2oLvfO1StjeXXHsAFjQeA.png" /></figure><p>2. We would be using the “Deploy to Amazon ECS” action workflow to create and push our docker image to ECR. From .github/workflows/aws.yml file, remove the last two steps with the name “Fill in the new image ID in the Amazon ECS task definition” and “Deploy Amazon ECS task definition”</p><p>3. Add one more “build image” step. We would be creating two docker images, one with an “out of the box” AWS docker image for Lambda and another one with docker hub python base image. In the latter image, we would be adding steps to make it compatible with Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*J5V-QuJ8zjnYSSm6_5rN-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*ohoWu9dELxtY90KD4NHoQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*17R_T3CQcv6F4XhwUI231Q.png" /></figure><p>Here are the docker files. The first one with the image provided by AWS for Lambda. And the second one I had created from python base image from docker hub and made it compatible with AWS Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*VvFkeejGBnLMOKbUb3C6Jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*s0UM3ypIfIm8CAYTgLCiyQ.png" /></figure><p>The command is referring to the “handler” function in the “lambda_handler.py” file in the source code root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8HU87ZJbwpyhKh7l2zDsQ.png" /></figure><p>Once the code is checked-in in the main branch. The deploy action would be triggered and it will create and push the docker images in ECR.</p><p>Now, let&#39;s create two Lambda functions with the docker images created above.</p><p>Go to Lambda in the AWS console and click create function. Select Container Image (Please note down the image URIs from the GitHub deploy workflow).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTgeQ-900IfscwKzrZ3CqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbSOtcv6b7R3B3hajrSO4w.png" /></figure><p>Provide function name and browse container image URI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8C2Xjpw_o-EDU3GcMeN4hw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Imyj9qrPJ8Mhb_HnkdW7oA.png" /></figure><p>Click Create Function and wait for the completion of function creation. After functions are created, click the test function to test the response return by the functions and also function logs.</p><p>So, Now we have docker images ready, CI/CD GitHub action ready and our functions ready. Next, we will add the Update function step in the GitHub action to update the Lambda functions with a new image on every check-in of our code in the main branch.</p><p>Go to “.github/workflows/aws.yml” in the GitHub source code repository and click edit. Add two new steps to run AWS CLI commands to update Lambda function as shown in the below images. The IMAGE_URI environment variable will reference the previous build image step with its id to get the image name from its output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b2gbfcLHIvQbnFtEXhbfNg.png" /></figure><p>Check-in the aws.yml file and voila. Your AWS Lambda is integrated with CI/CD pipeline in the GitHub source repository. Once the build is done, your AWS Lambda functions will be updated with the latest docker images.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfa3015b5ee0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>