Skip to content

Commit 304271e

Browse files
author
Alexander Melnyk
committed
docs: add examples for layer ARNs
1 parent 5d67f2c commit 304271e

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

Diff for: docs/index.md

+90-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,96 @@ Powertools is also available as a Lambda Layer with public ARNs in each region o
4040

4141
#### Public ARNs
4242

43-
We build, release and distribute packaged Lambda Powertools layers for each region. This means you can copy a specific ARN and use it in your Lambda deployment. The layer region must be in the same region as your lambda function. The public layers do not contain the `pydantic` library that is required for the `parser` utility.
43+
We build, release and distribute packaged Lambda Powertools layers for each region. This means you can copy a specific ARN and use it in your Lambda deployment. The layer region must be equal to the region of your lambda function. The public layers do not contain the `pydantic` library that is required for the `parser` utility.
44+
45+
46+
=== "SAM"
47+
48+
```yaml hl_lines="5"
49+
MyLambdaFunction:
50+
Type: AWS::Serverless::Function
51+
Properties:
52+
Layers:
53+
- arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:2
54+
```
55+
56+
=== "Serverless framework"
57+
58+
```yaml hl_lines="5"
59+
functions:
60+
main:
61+
handler: lambda_function.lambda_handler
62+
layers:
63+
- arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:2
64+
```
65+
66+
=== "CDK"
67+
68+
```python hl_lines="14"
69+
from aws_cdk import core, aws_lambda
70+
71+
class SampleApp(core.Construct):
72+
73+
def __init__(self, scope: core.Construct, id_: str) -> None:
74+
super().__init__(scope, id_)
75+
76+
aws_lambda.Function(self,
77+
'sample-app-lambda',
78+
runtime=aws_lambda.Runtime.PYTHON_3_8,
79+
function_name='sample-lambda',
80+
code=aws_lambda.Code.asset('./src'),
81+
handler='app.handler',
82+
layers: ["arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:2"]
83+
)
84+
```
85+
86+
=== "Terraform"
87+
88+
```terraform hl_lines="9 38"
89+
terraform {
90+
required_version = "~> 1.0.5"
91+
required_providers {
92+
aws = "~> 3.50.0"
93+
}
94+
}
95+
96+
provider "aws" {
97+
region = "us-east-1"
98+
}
99+
100+
resource "aws_iam_role" "iam_for_lambda" {
101+
name = "iam_for_lambda"
102+
103+
assume_role_policy = <<EOF
104+
{
105+
"Version": "2012-10-17",
106+
"Statement": [
107+
{
108+
"Action": "sts:AssumeRole",
109+
"Principal": {
110+
"Service": "lambda.amazonaws.com"
111+
},
112+
"Effect": "Allow",
113+
"Sid": ""
114+
}
115+
]
116+
}
117+
EOF
118+
}
119+
120+
resource "aws_lambda_function" "test_lambda" {
121+
filename = "lambda_function_payload.zip"
122+
function_name = "lambda_function_name"
123+
role = aws_iam_role.iam_for_lambda.arn
124+
handler = "index.test"
125+
runtime = "python3.8"
126+
layers = ["arn:aws:lambda:us-east-1:017000801446:layer:AWSLambdaPowertoolsPython:2"]
127+
128+
source_code_hash = filebase64sha256("lambda_function_payload.zip")
129+
}
130+
131+
132+
```
44133

45134
??? info "List of all regions and version with public AWS Lambda Powertools Layers"
46135

0 commit comments

Comments
 (0)