Skip to content

Commit 5be9116

Browse files
committed
updated readme and stack.py file
1 parent 2f764f0 commit 5be9116

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

Diff for: xray-lambdalayers-cdk-python/README.md

+49-26
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
# Overview
44

5-
This CDK example sets up AWS X-Ray for a Lambda function that uses Lambda Layers. The example demonstrates the use of the folder structure for a Lambda layer written in Python, and using constructs for deploying and using the layer and X-Ray.
5+
This CDK example sets up AWS X-Ray for a Lambda function that uses Lambda Layers. The example demonstrates the use of the folder structure for a Lambda layer written in Python, and using constructs for deploying and using the layer and X-Ray.
66

7+
Important: This application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
8+
9+
# Requirements
10+
11+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) (AWS CDK >= 2.1.0) installed
715

816
# Python Setup
917

@@ -19,80 +27,95 @@ you can create the virtualenv manually.
1927
To manually create a virtualenv on MacOS and Linux:
2028

2129
```
22-
$ python3 -m venv .venv
30+
python3 -m venv .venv
2331
```
2432

2533
After the init process completes and the virtualenv is created, you can use the following
2634
step to activate your virtualenv.
2735

2836
```
29-
$ source .venv/bin/activate
37+
source .venv/bin/activate
3038
```
3139

3240
If you are a Windows platform, you would activate the virtualenv like this:
3341

3442
```
35-
% .venv\Scripts\activate.bat
43+
.venv\Scripts\activate.bat
3644
```
3745

3846
Once the virtualenv is activated, you can install the required dependencies.
3947

4048
```
41-
$ pip install -r requirements.txt
49+
pip install -r requirements.txt
4250
```
4351
To add additional dependencies, for example other CDK libraries, just add
4452
them to your `setup.py` file and rerun the `pip install -r requirements.txt`
4553
command.
4654

47-
At this point you can now synthesize the CloudFormation template for this code.
48-
49-
```
50-
$ cdk synth
51-
```
52-
#CDK deploy
53-
54-
A Lambda layer is a .zip file archive that can contain additional code or data. When deployed, CDK creates a layer .zip asset to be stored in a staging bucket managed by CDK. To enable this the AWS account being used needs to be bootstrapped.
55+
# How to Run X-Ray on the Lambda function using layers
5556

56-
With default Profile,
57+
# Deployment Instructutions
58+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
5759

5860
```
59-
$ cdk bootstrap
61+
git clone https://github.com/aws-samples/serverless-patterns
6062
```
6163

62-
With specific profile,
64+
2. Change directory to the pattern directory:
6365

6466
```
65-
$ cdk bootstrap --profile test
67+
cd serverless-patterns/xray-lambdalayers-cdk-python
6668
```
67-
# How to Run X-Ray on the Lambda function using layers
6869

69-
# Deployment Instructutions
70-
1. Create a [lambda layer](https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_lambda/README.html#layers) for AWS X-Ray.
70+
3. Create a [lambda layer](https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_lambda/README.html#layers) for AWS X-Ray.
7171
To do this we'll install the python dependencies inside this folder: `lambda_layer_x_ray_stack/layers/`:
7272

7373
```
74-
pip install aws-xray-sdk -t lambda_layer_x_ray_stack/layers/xray/python/lib/python3.8/site-packages
74+
pip install aws-xray-sdk -t lambda_layer_x_ray_stack/layers/xray/python
7575
```
7676

7777
```
7878
pip install boto3 -t lambda_layer_x_ray_stack/layers/boto3/python
7979
```
8080

81+
4. Each bucket name has to be globally unique so update the source and resized bucket names by replacing < your-name > with your name and any random digits in the lambda_layer_x_ray_stack_stack.py file.
82+
83+
5. Update the pillow arn in the lambda_layer_x_ray_stack_stack.py file to the latest version in your region. See [Klayers](https://github.com/keithrozario/Klayers/tree/master/deployments/python3.8/arns) and select your region and the latest pillow package version arn.
84+
8185
```
82-
Create a lambda layer from the console and select specify an ARN. Go to [Library ARNS](https://github.com/keithrozario/Klayers/tree/master/deployments/python3.8/arns) and select your region and the latest pillow package version arn. Paste this into the console and click add.
86+
layerpillow = lambda_.LayerVersion.from_layer_version_arn(self, 'pillowlayerversion', 'Your_Region_Pillow_ARN')
8387
```
8488

85-
2. Deploy application via `cdk`:
89+
6. Deploy application via `cdk`:
90+
91+
At this point you can now synthesize the CloudFormation template for this code.
8692

8793
```
8894
cdk synth
89-
cdk deploy
9095
```
9196

97+
A Lambda layer is a .zip file archive that can contain additional code or data. When deployed, CDK creates a layer .zip asset to be stored in a staging bucket managed by CDK. To enable this the AWS account being used needs to be bootstrapped.
98+
99+
With default Profile,
100+
101+
```
102+
cdk bootstrap
103+
```
104+
105+
With specific profile,
106+
107+
```
108+
cdk bootstrap --profile test
109+
```
110+
111+
Now we can deploy our stack.
112+
```
113+
cdk deploy
114+
```
92115

93116
# Testing
94117

95-
On the AWS Mangement Console, navigate to the lambda function and invoke it a few times. Go to the AWS X-Ray service and check that a Service Map has been created and is displaying traces.
118+
On the AWS Mangement Console, navigate to the source S3 bucket and upload a few images. Go to the AWS X-Ray service and check that a Service Map has been created and is displaying traces.
96119

97120

98121
## Useful commands
@@ -108,4 +131,4 @@ Enjoy!
108131
# Documentation
109132

110133
1. AWS Documentation for using [AWS CDK in Python](https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-python.html)
111-
2. AWS Documentation for using [AWS Lambda with AWS X-Ray](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html)
134+
2. AWS Documentation for using [AWS Lambda with AWS X-Ray](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html)

Diff for: xray-lambdalayers-cdk-python/lambda_layer_x_ray_stack/lambda_layer_x_ray_stack_stack.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from importlib.resources import Package
12
from aws_cdk import (
23
Stack,
34
RemovalPolicy,
@@ -7,7 +8,6 @@
78
aws_lambda_event_sources as eventsources
89
)
910
from constructs import Construct
10-
from aws_xray_sdk.core.recorder import TRACING_NAME_KEY
1111
import os
1212

1313
class LambdaLayerXRayStackStack(Stack):
@@ -16,7 +16,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
1616
super().__init__(scope, construct_id, **kwargs)
1717

1818
# Change pillow arn to latest version in your region. See https://github.com/keithrozario/Klayers/tree/master/deployments/python3.8/arns
19-
layerpillow = lambda_.LayerVersion.from_layer_version_arn(self, 'pillowlayerversion', 'arn:aws:lambda:us-east-2:770693421928:layer:Klayers-python38-Pillow:14')
19+
layerpillow = lambda_.LayerVersion.from_layer_version_arn(self, 'pillowlayerversion', 'Your_Region_Pillow_ARN')
2020

2121
# --------------------------------------------------------
2222
# Create buckets for thumbnail

0 commit comments

Comments
 (0)