Originally published at https://jun711.github.io 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.
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.
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.
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.
Originally published at https://jun711.github.io on August 3, 2019.
Learn how to turn on reader view on Google Chrome, Mozilla Firefox and Safari browsers.
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.
Learn how to configure AWS SAM to enable Binary Response such as
image/jpeg etc from AWS Api Gateway with Lambda proxy integration.
In this walkthrough, I will use
application/zip for example.
To enable Api Gateway Binary Response, you can set
x-amazon-apigateway-binary-media-types in your API's definition body.
uri: # api-gateway-arn using Fn::Join
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.
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.
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
Originally published at https://jun711.github.io
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.
CodeStar is a service that unifies and streamlines the following AWS services to provide smooth CI/CD experience.
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.
Using multithreading in AWS Lambda can speed up your Lambda execution and reduce cost as Lambda charges in 100 ms unit.
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.
You can create a ThreadPoolExecutor instance using the following syntax. You can control number of concurrent workers / threads by setting
thread_pool_executor = ThreadPoolExecutor(max_workers=4)
Workers in this thread pool executor receives a task via 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
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…