« Previous 1 2 3
Serverless run times with custom Bash AWS Lambda layers
A Code Bash
Get Set, Go
Navigate up to the top-right part of the function's page (Figure 5). Once there, click on Configure test events to create a test with variables to be sent to the function.
In my case, I'm going to leave an empty set of variables and not pass anything to the Lambda function; instead, I'll just send an empty run command to the Lambda function. I do, however, need to add the name EmptyTest to the test event under Event name . In this example, I'll just use the Hello World template. Click Save once you've added the event name and run the test by clicking the Test button. Figure 6 shows a successful invocation of the Lambda function.
Look back at the payload's content in Figure 2. Note that it runs the jq
JSON formatting command and outputs I am a Bash command!
(Listing 1). Lo and behold, that's what is present in the CloudWatch logs. If you get stuck, CloudWatch is your friend. The AWS Management Console main page has more than one link to click to read the most recent logs for the Lambda function, so follow a link.
The End Is Nigh
I hope you agree that the sophisticated functionality illustrated in this article brings a welcome addition to Lambda functions for those not familiar with other languages. Imagine the number of legacy scripts that are too much work to refactor but would suit a serverless invocation.
With the ever-growing features available in AWS, the use of Lambda functions will only grow and, I suspect, continue at the exponential rate it has shown so far. I hope you will enjoy using Bash for serverless tasks in the future as much as I intend to. Now, let me think, where's that uptime dashboard script I wrote a few years ago?
Infos
- Lambda functions: https://aws.amazon.com/lambda/
- Bash scripts in AWS Lambda via Layers: https://github.com/gkrizek/bash-lambda-layer
- Graham Krizek: https://krizek.io/
- AWS Lambda layers: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
- Lambda limits: https://docs.aws.amazon.com/lambda/latest/dg/limits.html
- aws_lambda_layer_version: https://www.terraform.io/docs/providers/aws/r/lambda_layer_version.html
- Configuring the AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
- Bash in AWS Lambda README: https://github.com/gkrizek/bash-lambda-layer/blob/master/README.md
- bash-lambda-layer: https://github.com/gkrizek/bash-lambda-layer/blob/master/examples/example-basic.sh
- Code for this article: ftp://ftp.linux-magazine.com/pub/listings/admin-magazine.com/56/
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)