Distributed Tracing for AWS Lambda Functions

Setup

6 min

Lambda application, not yet manually instrumented

Prerequisites

Observability Workshop Instance

The Observability Workshop uses the Splunk4Ninjas - Observability workshop template in Splunk Show, which provides a pre-configured EC2 instance running Ubuntu.

Your workshop instructor will provide you with the credentials to your assigned workshop instance.

Your instance should have the following environment variables already set:

Note

Alternatively, you can deploy a local observability workshop instance using Multipass.

AWS Command Line Interface (awscli)

The AWS Command Line Interface, or awscli, is an API used to interact with AWS resources. In this workshop, it is used by certain scripts to interact with the resource you’ll deploy.

Your Splunk-issued workshop instance should already have the awscli installed.

Terraform

Terraform is an Infrastructure as Code (IaC) platform, used to deploy, manage and destroy resource by defining them in configuration files. Terraform employs HCL to define those resources, and supports multiple providers for various platforms and technologies.

We will be using Terraform at the command line in this workshop to deploy the following resources:

  1. AWS API Gateway
  2. Lambda Functions
  3. Kinesis Stream
  4. CloudWatch Log Groups
  5. S3 Bucket
    • and other supporting resources

Your Splunk-issued workshop instance should already have terraform installed.

Workshop Directory (lambda)

The Workshop Directory lambda is a repository that contains all the configuration files and scripts to complete both the auto-instrumentation and manual instrumentation of the example Lambda-based application we will be using today.

AWS & Terraform Variables

AWS

Note to the workshop instructor: create a new user in the target AWS account called lambda-workshop-user. Ensure it has full permissions to perform the required actions via Terraform. Create an access token for the lambda-workshop-user user and share the Access Key ID and Secret Access Key with the workshop participants. Delete the user when the workshop is complete.

The AWS CLI requires that you have credentials to be able to access and manage resources deployed by their services. Both Terraform and the Python scripts in this workshop require these variables to perform their tasks.

Create an IAM Role (Workshop Instructor Only)

Note to the workshop instructor: This step only needs to be completed once, as the IAM role created in this step will be shared by all workshop participants:

bash
cd ~/workshop/lambda/iam_role
terraform init
terraform plan
terraform apply 

Note to the workshop instructor: After the workshop is complete, cleanup the role as follows:

bash
cd ~/workshop/lambda/iam_role
terraform destroy

Terraform

Terraform supports the passing of variables to ensure sensitive or dynamic data is not hard-coded in your .tf configuration files, as well as to make those values reusable throughout your resource definitions.

In our workshop, Terraform requires variables necessary for deploying the Lambda functions with the right values for the OpenTelemetry Lambda layer; For the ingest values for Splunk Observability Cloud; And to make your environment and resources unique and immediatley recognizable.

Terraform variables are defined in the following manner:

We will be using a combination of variables.tf and terraform.tfvars files to set our variables in this workshop.

File Permissions

While all other files are fine as they are, the send_message.py script in both the auto and manual will have to be executed as part of our workshop. As a result, it needs to have the appropriate permissions to run as expected. Follow these instructions to set them.

Now that we’ve squared off the prerequisites, we can get started with the workshop!

Last Modified ·