Sign in

Originally published at on December 6, 2019.

Learn how to create a Lambda Layer using AWS SAM (Serverless Application Model) and CloudFormation in YAML to reuse code and reduce Lambda deployment size.

AWS Lambda Layers

Lambda Layers can be thought of as additional code added on top of a Lambda function. A Lambda Layer is a ZIP archive / file that contains code and can be imported by Lambda functions.

In other words, you can extract and reuse common code by keeping the code in a Lambda Layer and attach it to multiple Lambda functions.

As for limit, a Lambda function can…

Learn about HTML Inline Frame element (<iframe>) through some examples.

What is Iframe

HTML iframes are used to embed another webpage into a webpage. The embedded webpage can be from a different domain. However, for security reason, you will have limited control to the embedded webpage that is from a different origin.

Embed A Local Webpage

You can embed your own webpages using an iframe. For example, you have a homepage and webpage1. You can then embed webpage1 on your homepage using an iframe.

You can give it a try by downloading homepage.html and webpage1.html. Otherwise, you can save the following HTML in 2 files: homepage.html and…

Originally published at on August 3, 2019.

Learn how to turn on reader view on Google Chrome, Mozilla Firefox and Safari browsers.

Chrome Reader View

Since Chrome 75, there is an experimental reader view function where you can enable via Chrome settings.

1. To enable reader view, paste chrome://flags/#enable-reader-mode in your Chrome address bar and you will see an experimental feature page. Enable reader mode by toggling the button next to it.

Learn how to update AWS Cloud9 IDE(Integrated development environment) AWS SAM(Serverless Application Model) CLI(command-line interface) version.

As of 2019–07–16, when you create a new AWS CodeStar project with Cloud9 as IDE, its environment is installed with AWS SAM CLI version 0.2.11 but the latest SAM CLI version is 0.18.0


The following issues caused by required functionalities not supported by older SAM CLI versions. They can be solved by updating AWS SAM CLI version to a later version that supports it.

  1. AWS Cloud9 IDE fails to invoke(run local an AWS Resources) a local Lambda function that has python3.7 as runtime. It…

Learn how to configure AWS SAM to enable Binary Response such as audio/mpeg, application/zip, image/jpeg etc from AWS Api Gateway with Lambda proxy integration.


In this walkthrough, I will use application/zip for example.

1. CloudFormation yaml

To enable Api Gateway Binary Response, you can set x-amazon-apigateway-binary-media-types in your API's definition body.

Type: AWS::Serverless::Api
StageName: Prod
swagger: '2.0'
basePath: '/Prod'
- 'https'
- "application/json"
responses: {}
uri: # api-gateway-arn using Fn::Join
responses: {}
passthroughBehavior: "when_no_match"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws_proxy"
- "application/zip"


Even though AWS SAM provide BinaryMediaTypes property but as of Aug…

Learn how to invoke AWS Lambda functions on your machine using AWS SAM CLI.


You will need to install AWS CLI, AWS SAM CLI and Docker to invoke a Lambda function locally. If you already have AWS CLI installed, you can skip to step 2.

This is to assume you have AWS CLI installed. If not, you can follow steps on AWS CLI installation document to install AWS CLI.

1. Installing AWS CLI

You need to have at least Python 2.6+ or Python 3.3+ to install AWS CLI. The following is the command to install AWS CLI.

$ pip3 install awscli --upgrade --user $…

Learn how to create multiple API Gateway deployment stages even though AWS SAM replaces previous stages in subsequent deployments.

Note that this is a workaround to AWS SAM template replaces previously deployed stage when you change API StageName property on yaml. It is probably not an optimal solution as it involves an extra step after deployment via CodePipeline.


Follow the following steps to adopt this workaround.

1. Specify Stage Name

In your yaml file, specify stage name that you want CodePipeline to deploy to. For example, set it as ‘Prod’ if you want it to deploy to Prod stage.

Type: AWS::Serverless::Api

Originally published at

Learn how to create development and production pipelines for your web service projects using AWS CodePipeline and AWS CodeStar. Having a development and a production pipeline can streamline development and production workflow.

AWS CodeStar

CodeStar is a service that unifies and streamlines the following AWS services to provide smooth CI/CD experience.

  1. AWS CodeCommit
  2. AWS CodeBuild
  3. AWS CloudFormation
  4. Amazon CloudWatch
  5. AWS Cloud9

Quoted from AWS CodeStar page:

AWS CodeStar provides a unified user interface, enabling you to easily manage your software development activities in one place. …

An example of using Python multi-threading in AWS Lambda.

Why Multi Threading

Using multithreading in AWS Lambda can speed up your Lambda execution and reduce cost as Lambda charges in 100 ms unit.

Python ThreadPoolExecutor

Note that ThreadPoolExecutor is available with Python 3.6 and 3.7+ runtime. ThreadPoolExecutor provides a simple abstraction to using multiple threads to perform tasks concurrently.

Creating a ThreadPoolExecutor

You can create a ThreadPoolExecutor instance using the following syntax. You can control number of concurrent workers / threads by setting max_workers parameter.

thread_pool_executor = ThreadPoolExecutor(max_workers=4)

Submit A Task To Worker

Workers in this thread pool executor receives a task via ThreadPoolExecutor submit method.


Free Resources

ThreadPoolExecutor shutdown method with…

Learn how to provide API Gateway permission to invoke Lambda function(s).


API Gateway endpoint can’t invoke Lambda with 5XX permission error.

When testing on API Gateway console, you see this error message:

Execution log for request d237e276–656e-11e9-aaff-51e803313fb3… truncatedDate : Sending request to https://lambda.function.url
Date : Execution failed due to configuration error:
Invalid permissions on Lambda function
Date : Method completed with status: 500

Expected Behaviour

Published API is able to invoke AWS Lambda functions successfully.


Why didn’t it work? The reason is we have to explicitly specify the ARN of an IAM role for API Gateway to assume when invoking…


Software Engineer and Blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store