Skip to content

Commit f9143b4

Browse files
authored
Add README for Lambda layer (#258)
*Issue #, if available:* *Description of changes:* By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent f003a1f commit f9143b4

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

lambda-layer/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# AWS Lambda Application Signals Support
2+
3+
This package provides support for **Application Signals** in AWS Lambda environment.
4+
5+
## Features
6+
7+
- Supports Application Signals, including traces and metrics, for AWS Lambda Python Runtimes.
8+
- Automates the deployment process, including the creation of the Application Python Lambda Layer and a sample Lambda function.
9+
10+
## Prerequisites
11+
12+
Before you begin, make sure you have installed and configured the following tools:
13+
14+
- [Docker](https://www.docker.com/get-started)
15+
- [Terraform](https://www.terraform.io/downloads)
16+
- [AWS CLI](https://aws.amazon.com/cli/) (to configure AWS credentials)
17+
18+
### Configure AWS Credentials
19+
20+
Ensure that your AWS credentials are properly configured in your local environment. You can use the following command with the AWS CLI:
21+
22+
```bash
23+
aws configure
24+
```
25+
This will prompt you to enter your `AWS Access Key ID`, `AWS Secret Access Key`, `Default region name`, and `Default output format`.
26+
27+
## Installation and Deployment
28+
29+
### 1. Clone the Repository
30+
31+
First, clone this repository to your local machine:
32+
33+
```bash
34+
git clone https://github.com/yourusername/your-repo.git
35+
```
36+
37+
### 2. Run the Build Script
38+
39+
Navigate to the `lambda-layer` folder and run the `build.sh` script. This will create the Application Python Lambda Layer and a Lambda sample app in your AWS account:
40+
41+
```bash
42+
cd lambda-layer
43+
./build.sh
44+
```
45+
46+
## Lambda Sample App
47+
48+
Once the script has successfully run, you will see the deployed Lambda sample app in your AWS account. You can trigger the
49+
Lambda function and view the traces and metrics through the AWS CloudWatch Console.

lambda-layer/src/Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
ARG runtime=python3.12
2-
3-
FROM public.ecr.aws/sam/build-${runtime}
1+
FROM public.ecr.aws/sam/build-python3.12 AS python312
42

53
ADD . /workspace
64

@@ -14,10 +12,20 @@ RUN mkdir -p /build && \
1412
python3 -m pip install aws-opentelemetry-distro/ -t /build/python && \
1513
mv otel_wrapper.py /build/python && \
1614
mv otel-instrument /build && \
15+
python3 -m compileall /build/python && \
1716
chmod 755 /build/otel-instrument && \
18-
rm -rf /build/python/boto* && \
19-
rm -rf /build/python/urllib3* && \
20-
cd /build && \
17+
rm -rf /build/python/urllib3*
18+
19+
20+
FROM public.ecr.aws/sam/build-python3.11 AS python311
21+
22+
WORKDIR /workspace
23+
24+
COPY --from=python312 /build /build
25+
26+
RUN python3 -m compileall /build/python
27+
28+
RUN cd /build && \
2129
zip -r aws-opentelemetry-python-layer.zip otel-instrument python
2230

2331
CMD ["cp", "/build/aws-opentelemetry-python-layer.zip", "/out/aws-opentelemetry-python-layer.zip"]

lambda-layer/src/otel-instrument

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,13 @@ export PYTHONPATH="$LAMBDA_LAYER_PKGS_DIR:$PYTHONPATH";
8484

8585
export PYTHONPATH="$LAMBDA_RUNTIME_DIR:$PYTHONPATH";
8686

87-
# Configure OpenTelemetry Python with environment variables
88-
89-
# - We leave `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` to its default. This is
90-
# `http://localhost:4318/v1/traces` because we are using the HTTP exporter
91-
92-
# - If OTEL_EXPORTER_OTLP_PROTOCOL is not set by user, the default exporting protocol is http/protobuf.
93-
if [ -z "${OTEL_EXPORTER_OTLP_PROTOCOL}" ]; then
94-
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
95-
fi
9687

9788
# - Set the service name
9889

9990
if [ -z "${OTEL_SERVICE_NAME}" ]; then
10091
export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME;
10192
fi
10293

103-
# - Set the propagators
104-
105-
if [[ -z "$OTEL_PROPAGATORS" ]]; then
106-
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
107-
fi
10894

10995
export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME,aws.log.group.names=$AWS_LAMBDA_LOG_GROUP_NAME";
11096

0 commit comments

Comments
 (0)