You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xray-lambdalayers-cdk-python/README.md
+49-26
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,16 @@
2
2
3
3
# Overview
4
4
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.
6
6
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
@@ -19,80 +27,95 @@ you can create the virtualenv manually.
19
27
To manually create a virtualenv on MacOS and Linux:
20
28
21
29
```
22
-
$ python3 -m venv .venv
30
+
python3 -m venv .venv
23
31
```
24
32
25
33
After the init process completes and the virtualenv is created, you can use the following
26
34
step to activate your virtualenv.
27
35
28
36
```
29
-
$ source .venv/bin/activate
37
+
source .venv/bin/activate
30
38
```
31
39
32
40
If you are a Windows platform, you would activate the virtualenv like this:
33
41
34
42
```
35
-
% .venv\Scripts\activate.bat
43
+
.venv\Scripts\activate.bat
36
44
```
37
45
38
46
Once the virtualenv is activated, you can install the required dependencies.
39
47
40
48
```
41
-
$ pip install -r requirements.txt
49
+
pip install -r requirements.txt
42
50
```
43
51
To add additional dependencies, for example other CDK libraries, just add
44
52
them to your `setup.py` file and rerun the `pip install -r requirements.txt`
45
53
command.
46
54
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
55
56
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:
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
+
81
85
```
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.
At this point you can now synthesize the CloudFormation template for this code.
86
92
87
93
```
88
94
cdk synth
89
-
cdk deploy
90
95
```
91
96
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
+
```
92
115
93
116
# Testing
94
117
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.
96
119
97
120
98
121
## Useful commands
@@ -108,4 +131,4 @@ Enjoy!
108
131
# Documentation
109
132
110
133
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)
0 commit comments