AWS Lambda

Marcelo Cure
AWS Tip
Published in
4 min readApr 22, 2024

--

I have been working a lot with AWS Lambda in the past years, and I’d like to share some concepts, tips, opinions and guides on how to use it.

What is AWS Lambda?

AWS Lambda is a serverless function, obviously managed by AWS, that is used for short running processes.

Lambda’s default timeout is 30 seconds, which indicates that it should not have long running processes.

You can deploy your code to your AWS Lambda function using:

  • docker images from ECR
  • upload zip file
  • load from s3

As lambdas code base must be small, I always used it uploading zip files built on my pipeline. Also there are good integrations for CI/CD tools such as Bitbucket Pipelines.

Languages

AWS lambda supports some of the most used languages/runtimes

  • Nodejs (versions 16.x.x to 20.x.x)
  • Python (versions 3.8 to 3.12)
  • Java (versions 8 to 21)
  • Ruby (versions 3.2 to 3.3)
  • .NET (versions 6 to 8)

To be honest I prefer using python / nodejs as they are less burocratic :)

Integrations

Lambdas come with various integration options, they are divided in triggers and destinations.

Triggers

These are integrations that can trigger the function, I’m not gonna list all of them, but I’ll explain some:

  • Lambdas can listen to a SQS queue
  • Lambdas can be a subscription of a SNS topic
  • Lambdas can listen to a S3 bucket
  • Lambdas can be called from Event Bridge schedulers
  • Api Gateways and ALBs also can reference and be a trigger of a lambda function
  • Apart from that other nice integrations are: DynamoDB, DocumentDB, Kinesis, Amazon MQ, CodeCommit
  • And other aws integrations like: Alexa, Auth0, Datadog, Shopify, SignalFX among other

Destinations

In the end of a function execution, the output can be sent to external services according to the status, success or failure. Here the options are more limited, but still useful:

  • Lambdas can post a output message on a SNS topic
  • Lambdas can post a output message on a SQS queue
  • Lambdas can trigger another lambda with the output
  • Lambdas can send events to EventBridge event bus

There are some exceptions, such as: you cannot have a trigger and a destination of the same integration for SQS.

Limitations

Lambdas also have some limitations and I’d like to list some here:

  • Lambdas cannot return files
  • Execution timeout is limited to 15 minutes
  • Max memory allocation is 10240 MB (min is 128MB).
  • Disk space (ephemeral) is limited to 10240 MB (min is 512MB).
  • The default deployment package size is 50 MB.

In most cases, these limitations are not big problems.

Configuration

On the tab Code you can configure the runtime settings where you can define the runtime, the handler (file name.function name) and the architecture

Most of the configuration is located on the tab Configuration (really?).

There you can configure environment variables, network configuration (VPC, subnets and security groups), you can create a function URL, among other configurations, I’ll leave a screenshot of the menu below:

The basic configuration is also a important menu where you can configure memory, storage and timeouts, see below:

Lambda cold start

There is a initial delay experienced when an AWS Lambda function is invoked for the first time or after being idle for some time, this is called “cold start”.

According to a AWS study, cold start impacts just 1% of the lambda invocations, but that’s something you need to consider depending on your use case.

AWS release the provisioned concurrency which will guarantee the lowest possible latency. According to AWS:

This feature keeps your functions initialized and warm, ready to respond in double-digit milliseconds at the scale you provision. Unlike on-demand Lambda functions, this means that all setup activities happen ahead of invocation, including running the initialization code.

Here is a good AWS reference for Lambda performance.

The idea of this post was to bring some basic/mid-knowledge about AWS Lambdas and a bit of my experience.

I really hope I helped you to understand some things that are important to consider when using AWS Lambdas and serverless in general.

Feel free to comment here if you wanna discuss more about it.

--

--