Run Lambda Functions on a Schedule using Amazon EventBridge Event Rules

Amazon EventBridge is a serverless event bus service that makes it easy to connect your applications with data from a variety of sources. You can create rules that self-trigger on an automated schedule in EventBridge using cron or rate expressions. These rules can in-turn trigger Lambda functions, even with custom input if required. All scheduledContinue reading “Run Lambda Functions on a Schedule using Amazon EventBridge Event Rules”

Use Pre-Installed Terraform Plugins Instead of Downloading them with “terraform init”

In normal usage, terraform init downloads & installs the plugins for any providers used in the configuration automatically in the .terraform directory. It’s sometimes desirable to disable this behavior, either because you wanna do away with the re-download every time on your dev system, or because you’re running Terraform in a CI/CD pipeline where it’sContinue reading “Use Pre-Installed Terraform Plugins Instead of Downloading them with “terraform init””

Terraform State Management in Multi-Customer Multi-Account Multi-Environment Scenarios

This post explores ways to structure your Terraform configuration when it’s to be used to deploy infrastructure across multiple cloud accounts, for multiple customers of yours & for multiple environments for each app involved — development, staging, production. One prime example where this might be very useful to you is if you build a multi-tenantContinue reading “Terraform State Management in Multi-Customer Multi-Account Multi-Environment Scenarios”

How Amazon RDS Aurora MySQL Cross-Region Replication Really Works Under the Hood

RDS Aurora MySQL in AWS provides an in-built feature to create a cross-region read replica of a database. This is easily accessible from the console as shown below: This article describes at a high-level the basic logistics of how replication really happens. First things first: How MySQL Binlog Replication Works The MySQL replication feature allowsContinue reading “How Amazon RDS Aurora MySQL Cross-Region Replication Really Works Under the Hood”

Run Celery Tasks in the Background with a Django App in AWS Elastic Beanstalk

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. Celery is a task queue implementationContinue reading “Run Celery Tasks in the Background with a Django App in AWS Elastic Beanstalk”

Troubleshooting Permission Denied Errors When Trying to SSH Into an AWS EC2 Instance

If you’re new to AWS (or not), you might run into issues trying to SSH into EC2 instances. This article summarizes things you can try to fix the issue. If you get “Permission denied (publickey)” error or simply aren’t able to SSH to an instance, try the following: Ensure the file permissions on the privateContinue reading “Troubleshooting Permission Denied Errors When Trying to SSH Into an AWS EC2 Instance”

How to Make All Objects in an Amazon S3 Bucket Public by Default?

There are several ways to make objects in an S3 bucket public. The first is to use the following bucket policy: This (& other) policies can be generated using AWS’s official policy generator at awspolicygen.s3.amazonaws.com/policygen.html: You can also use the (legacy) Access Control Lists to allow public read: If you’re using the S3 CLI toContinue reading “How to Make All Objects in an Amazon S3 Bucket Public by Default?”

Enhance API Client Experience by Deploying a CloudFront Distribution to Serve APIs from Amazon API Gateway

Just like you speed-up delivery of your static assets from S3 buckets using CloudFront CDN, you can do the same for your APIs as well. In most cases, it’s enough to make your API “edge-optimized”: If you do this, API Gateway creates & manages a CloudFront distribution for you behind the scenes, but if youContinue reading “Enhance API Client Experience by Deploying a CloudFront Distribution to Serve APIs from Amazon API Gateway”

“dial tcp: lookup example.com on 8.8.8.8:53: server misbehaving” After Transferring Your Domain Over to Amazon Route 53

So you moved your domain to Route 53, created a hosted zone with all the right records & yet when you visit your domain every after days after this change, you see the error “dial tcp: lookup example.com on 8.8.8.8:53: server misbehaving” & when you try DNS lookup, it says it does not have anyContinue reading ““dial tcp: lookup example.com on 8.8.8.8:53: server misbehaving” After Transferring Your Domain Over to Amazon Route 53″

Why Use Private Subnets in a VPC When Instances Without a Public IP in Public Subnets are Private Anyway?

What is the point of having private subnets at all when you can simply take away an EC2 instance’s public IP to make it private? The main difference between a public & private subnet is what the subnet’s default route is, in the VPC’s routing tables. This determines the validity of public IPs on instancesContinue reading “Why Use Private Subnets in a VPC When Instances Without a Public IP in Public Subnets are Private Anyway?”

“The specified key does not exist” for Static Websites Hosted on S3 behind CloudFront

If you’ve deployed a static website on an S3 bucket behind a CloudFront distribution & encountered the following error when you navigate the site, this post is for you. Weirdly, this will work if you hit the same object’s S3 URL directly, but not if you go via CloudFront. So what’s going on here? Let’sContinue reading ““The specified key does not exist” for Static Websites Hosted on S3 behind CloudFront”

Lambda Calling Lambda

There are many ways for a Lambda function to invoke another Lambda function. The first is to use the AWS SDK directly. JavaScript Here’s an example using the JavaScript SDK: See Lambda.invoke’s documentation here. Python The same can be done using Boto 3: That’s async invocation. For sync, do this: Java Here’s a detailed blogContinue reading “Lambda Calling Lambda”

Access Query Strings, Path Parameters & HTTP Headers in Lambda Functions Behind Amazon API Gateway

It’s common for APIs to have parameters, either as query strings — GET /object?name=book — or as path parameters — GET /object/book. But if your APIs are implemented in Lambda functions, how do you access the values of these parameters in a Lambda function? Here are a few ways: Using Lambda Proxy Integration Turn onContinue reading “Access Query Strings, Path Parameters & HTTP Headers in Lambda Functions Behind Amazon API Gateway”

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

AWS4-HMAC-SHA256, also known as Signature Version 4 or Sig v4 is 1 of 2 authentication mechanisms supported by S3. All AWS regions support Sig v4 but N. Virginia (US East 1) & many others also support the older Sig v2. Amazon S3 supports Signature Version 4, a protocol for authenticating inbound API requests to AWSContinue reading “The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.”

Download Part of a Large GitHub Repo Using SVN

Whether you’re using “microservices in a monorepo” design or just need a subdirectory of a large GitHub repo, you definitely don’t have to clone the entire repo to work with just a handful of files. Instead, use GitHub’s ability to convert any to repo to SVN, to get just the files you need.

Enable/Disable AWS Lambda Triggers Programmatically by Invoking an API

Lambda functions can be triggered by a number of sources by creating event source mappings, but if you need to enable/disable these mappings programmatically, to control when the Lambda function triggers, the most straightforward way is to call Lambda’s UpdateEventSourceMapping API. But if for some reason, you need your own API wrapper over this API, API Gateway is the way to go. This post explains how to set up an API in API Gateway to enable/disable your Lambda triggers.

Protect AWS Lambda Environment Variables from Prying Eyes by Encrypting Them in Transit

Lambda environment variables are encrypted at rest by default but anyone with access to the Lambda console of your AWS account can see the values of your environment variables. This is fine for variables like database endpoints but not good for variables that store some kind of secret, like a database password for example. This post shows you how to obfuscate & protect them.

Automatically Shutdown Your API on Amazon API Gateway When It Breaches a Certain Spending Threshold

Amazon API Gateway provides usage plans with quotas that can be used to limit the number of requests to your API. Quotas are enforced on a per-customer basis. This is the proper design for most real-world API projects. But what if you’re building small-scale projects or personal projects where the cost incurred to you by your API in your AWS account is the biggest concern. What if you have a hard spending limit for API Gateway in your AWS account & you’re OK with shutting down the API for everyone as soon as the spending limit is reached. This post shows you how to do just that.

How to Enforce a Quota on the CORS OPTIONS Method in Amazon API Gateway

Amazon API Gateway supports usage plans which contain quotas to limit the number of requests a user can make to your API in a given time period. Quotas work by inspecting the HTTP header carrying the API key in every incoming request. But what about requests that do not or cannot support specifying API keys? API Gateway cannot enforce any quotas on them. One such request is the HTTP OPTIONS method used by browsers in preflight requests to determine the CORS status of API endpoints, before making the actual call to the API. This article describes a way to use WAF to limit OPTIONS calls.

Version Control & Auto-Deploy your Files Stored in Amazon EFS

Although the primary use case of Amazon EFS is to be used as an NFS, occasionally it could hold the kind of data that lends well to version control. A WordPress installation is one such example. And where there is version control, automated deployment pipelines aren’t far behind. This article describes a way for you to automatically deploy files from a CodeCommit repository to an EFS file system, whenever a change is pushed to the repo.

Cross-Account Usage of Amazon Simple Email Service (SES) — Route All Your Emails via a Single AWS Account in a Multi-Account Setup

It’s fairly common in enterprises to have multiple AWS accounts for different environments: dev/test, staging/QA, prod/preprod, etc. Often there’s a shared services account which hosts all services that other accounts need. One such service is sending emails. This article explains how to set up SES in the shared account & use it to send emails from a Lambda function running in the dev or prod account.

Massively Improve WordPress Performance & Security by Turning it into a Static Site on Amazon S3

WordPress is awesome! It powers 37% of the internet & is the most beloved CMS out there. But like everything else, it can always be improved. If you’re using WordPress to serve up a simple website with occasionally changing content, then you can benefit a lot by turning it into a static site. You don’t have to get rid of WordPress though. Keep using it for the ease of content generation, but convert everything into plain-old HTML & CSS before serving it to the world. Here’s how to do that.

One-Click Generate & Copy Unique Names / UUIDs for Your Cloud Resources

If you spend a lot of time managing cloud infrastructure manually via the cloud provider’s web console, you often need to come up with unique names for your cloud resources. You probably have a naming convention in place for most cloud services that you work with, but when it comes to global services like Amazon S3, you must resort to unique alpha-numeric “generated” identifier strings for at least a portion of the resource name. This article provides a one-click generate & copy solution for such names. All you have to do is click & paste!

Demystifying Database Connection Pools in AWS Lambda Functions

It’s a common practice in traditional applications to maintain a pool of ready-to-use database connections, instead of creating one from scratch every time a piece of code needs to talk to the database. But what happens if you do the same in Lambda functions? Each function is separate from the other & cannot share the pool. How do connection pools behave then? Are they even required? How should you size them? This article aims to explore these questions & explain in detail how database connection pools behave in Lambda functions.

Bypass the 50 MB Lambda Deployment Package Size Limit by Deploying via S3

AWS Lambda doesn’t allow the deployment package of a Lambda function to be larger than 50 MB in size. But that’s only when you upload the package directly to the function. If instead, you upload the package to S3 & provide the S3 URL to the Lambda function, you can get away with deployment packages up to 250 MB in size (uncompressed)!

Archive & Delete Old Data from an Amazon RDS Aurora MySQL Database

Over time, as the data in your production database grows, it will inevitably degrade the DB’s performance. When that happens, you know it’s time to get rid of some of that years old data. But of course, you can’t just delete it. You have to archive it first. This article describes a cloud-native way of doing this.

Grant Temporary Access to an IAM User or Group to Another AWS Account

Say you have 2 AWS accounts, 1 for dev & 1 for prod. Now in most cases, devs have no access to prod & that’s how it should be. But when things break in prod, it would help to let the devs take a look in there. This article explains how to grant devs temporary access to prod & revoke it right after.

Create a Full-Fledged Serverless API Backend, Complete with a Database & CI/CD Pipeline, in Just a Few Clicks!

In this article, you’ll see how easy it is to create a serverless API backend using AWS Lambda functions & Amazon API Gateway, backed by the NoSQL DynamoDB database, by deploying a sample Lambda application. This sample also comes with a CodeBuild project & a CodePipeline to fully automate deployments. It’ll even create a Git repository for you in CodeCommit so you can simply clone the repo & start building on top of the sample.