Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f99a7f3

Browse files
committedMay 21, 2024·
Moving files + small fix
1 parent 7fb1ad5 commit f99a7f3

26 files changed

+310
-272
lines changed
 

‎.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repos:
3434
entry: poetry run cfn-lint
3535
language: system
3636
types: [yaml]
37+
exclude: examples/homepage/install/.*?/serverless\.yml$
3738
files: examples/.*
3839
- repo: https://github.com/rhysd/actionlint
3940
rev: "fd7ba3c382e13dcc0248e425b4cbc3f1185fa3ee" # v1.6.24

‎docs/index.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,76 +76,76 @@ You can install Powertools for AWS Lambda (Python) using your favorite dependenc
7676

7777
=== "SAM"
7878

79-
```yaml hl_lines="6"
80-
--8<-- "examples/install/x86_64/sam.yaml"
79+
```yaml hl_lines="11"
80+
--8<-- "examples/homepage/install/x86_64/sam.yaml"
8181
```
8282

8383
=== "Serverless framework"
8484

85-
```yaml hl_lines="5"
86-
--8<-- "examples/install/x86_64/serverless.yaml"
85+
```yaml hl_lines="13"
86+
--8<-- "examples/homepage/install/x86_64/serverless.yml"
8787
```
8888

8989
=== "CDK"
9090

91-
```python hl_lines="16 21"
92-
--8<-- "examples/install/x86_64/cdk.py"
91+
```python hl_lines="13 19"
92+
--8<-- "examples/homepage/install/x86_64/cdk.py"
9393
```
9494

9595
=== "Terraform"
9696

9797
```terraform hl_lines="9 37"
98-
--8<-- "examples/install/x86_64/terraform.tf"
98+
--8<-- "examples/homepage/install/x86_64/terraform.tf"
9999
```
100100

101101
=== "Pulumi"
102102

103-
```python hl_lines="22"
104-
--8<-- "examples/install/x86_64/pulumi.py"
103+
```python hl_lines="21-27"
104+
--8<-- "examples/homepage/install/x86_64/pulumi.py"
105105
```
106106

107107
=== "Amplify"
108108

109-
```zsh
110-
--8<-- "examples/install/x86_64/amplify.txt"
109+
```zsh hl_lines="9"
110+
--8<-- "examples/homepage/install/x86_64/amplify.txt"
111111
```
112112

113113
=== "arm64"
114114

115115
=== "SAM"
116116

117-
```yaml hl_lines="7"
118-
--8<-- "examples/install/arm64/sam.yaml"
117+
```yaml hl_lines="12"
118+
--8<-- "examples/homepage/install/arm64/sam.yaml"
119119
```
120120

121121
=== "Serverless framework"
122122

123-
```yaml hl_lines="6"
124-
--8<-- "examples/install/arm64/serverless.yaml"
123+
```yaml hl_lines="13"
124+
--8<-- "examples/homepage/install/arm64/serverless.yml"
125125
```
126126

127127
=== "CDK"
128128

129-
```python hl_lines="16 21"
130-
--8<-- "examples/install/arm64/cdk.py"
129+
```python hl_lines="13 19"
130+
--8<-- "examples/homepage/install/arm64/cdk.py"
131131
```
132132

133133
=== "Terraform"
134134

135135
```terraform hl_lines="9 37"
136-
--8<-- "examples/install/arm64/terraform.tf"
136+
--8<-- "examples/homepage/install/arm64/terraform.tf"
137137
```
138138

139139
=== "Pulumi"
140140

141-
```python
142-
--8<-- "examples/install/arm64/pulumi.py"
141+
```python hl_lines="21-27"
142+
--8<-- "examples/homepage/install/arm64/pulumi.py"
143143
```
144144

145145
=== "Amplify"
146146

147-
```zsh
148-
--8<-- "examples/install/arm64/amplify.txt"
147+
```zsh hl_lines="9"
148+
--8<-- "examples/homepage/install/arm64/amplify.txt"
149149
```
150150

151151
### Local development
@@ -262,34 +262,34 @@ Compared with the [public Layer ARN](#lambda-layer) option, SAR allows you to ch
262262

263263
=== "SAM"
264264

265-
```yaml hl_lines="6-7 13-14"
266-
--8<-- "examples/install/sar/sam.yaml"
265+
```yaml hl_lines="6 9 10 17-19"
266+
--8<-- "examples/homepage/install/sar/sam.yaml"
267267
```
268268

269269
=== "Serverless framework"
270270

271-
```yaml hl_lines="5 8 10-11"
272-
--8<-- "examples/install/sar/serverless.yaml"
271+
```yaml hl_lines="11 12 19 20"
272+
--8<-- "examples/homepage/install/sar/serverless.yml"
273273
```
274274

275275
=== "CDK"
276276

277-
```python hl_lines="19 27-28 36"
278-
--8<-- "examples/install/sar/cdk.py"
277+
```python hl_lines="7 16-20 23-27"
278+
--8<-- "examples/homepage/install/sar/cdk.py"
279279
```
280280

281281
=== "Terraform"
282282

283283
> Credits to [Dani Comnea](https://github.com/DanyC97){target="_blank" rel="nofollow"} for providing the Terraform equivalent.
284284

285285
```terraform hl_lines="12-13 15-20 23-25 40"
286-
--8<-- "examples/install/sar/terraform.tf"
286+
--8<-- "examples/homepage/install/sar/terraform.tf"
287287
```
288288

289289
Credits to [mwarkentin](https://github.com/mwarkentin){target="_blank" rel="nofollow"} for providing the scoped down IAM permissions below.
290290

291291
```yaml hl_lines="21-52" title="Least-privileged IAM permissions SAM example"
292-
--8<-- "examples/install/sar/scoped_down_iam.yaml"
292+
--8<-- "examples/homepage/install/sar/scoped_down_iam.yaml"
293293
```
294294

295295
## Quick getting started
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from aws_cdk import (
2-
Stack,
3-
aws_lambda,
4-
Aws
5-
)
1+
from aws_cdk import Aws, Stack, aws_lambda
62
from constructs import Construct
73

4+
85
class SampleApp(Stack):
96

107
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
@@ -13,13 +10,14 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
1310
powertools_layer = aws_lambda.LayerVersion.from_layer_version_arn(
1411
self,
1512
id="lambda-powertools",
16-
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69"
13+
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69",
1714
)
18-
aws_lambda.Function(self,
19-
'sample-app-lambda',
15+
aws_lambda.Function(
16+
self,
17+
"sample-app-lambda",
2018
runtime=aws_lambda.Runtime.PYTHON_3_12,
2119
layers=[powertools_layer],
2220
architecture=aws_lambda.Architecture.ARM_64,
23-
code=aws_lambda.Code.from_asset('lambda'),
24-
handler='hello.handler'
21+
code=aws_lambda.Code.from_asset("lambda"),
22+
handler="hello.handler",
2523
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import json
2+
3+
import pulumi
4+
import pulumi_aws as aws
5+
6+
role = aws.iam.Role(
7+
"role",
8+
assume_role_policy=json.dumps(
9+
{
10+
"Version": "2012-10-17",
11+
"Statement": [
12+
{"Action": "sts:AssumeRole", "Principal": {"Service": "lambda.amazonaws.com"}, "Effect": "Allow"},
13+
],
14+
},
15+
),
16+
managed_policy_arns=[aws.iam.ManagedPolicy.AWS_LAMBDA_BASIC_EXECUTION_ROLE],
17+
)
18+
19+
lambda_function = aws.lambda_.Function(
20+
"function",
21+
layers=[
22+
pulumi.Output.concat(
23+
"arn:aws:lambda:",
24+
aws.get_region_output().name,
25+
":017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69",
26+
),
27+
],
28+
tracing_config={"mode": "Active"},
29+
runtime=aws.lambda_.Runtime.PYTHON3D9,
30+
handler="index.handler",
31+
role=role.arn,
32+
architectures=["arm64"],
33+
code=pulumi.FileArchive("lambda_function_payload.zip"),
34+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
14
Resources:
25
MyLambdaFunction:
36
Type: AWS::Serverless::Function
47
Properties:
58
Architectures: [arm64]
9+
Runtime: python3.12
10+
Handler: app.lambda_handler
611
Layers:
712
- !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
service: powertools-lambda
2+
3+
provider:
4+
name: aws
5+
runtime: python3.12
6+
region: us-east-1
7+
8+
functions:
9+
powertools:
10+
handler: lambda_function.lambda_handler
11+
architecture: arm64
12+
layers:
13+
- arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69

‎examples/install/arm64/terraform.tf renamed to ‎examples/homepage/install/arm64/terraform.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77

88
provider "aws" {
9-
region = "{region}"
9+
region = "{region}"
1010
}
1111

1212
resource "aws_iam_role" "iam_for_lambda" {
@@ -26,7 +26,7 @@ resource "aws_iam_role" "iam_for_lambda" {
2626
]
2727
}
2828
EOF
29-
}
29+
}
3030

3131
resource "aws_lambda_function" "test_lambda" {
3232
filename = "lambda_function_payload.zip"

‎examples/homepage/install/sar/cdk.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from aws_cdk import Stack, aws_lambda, aws_sam
2+
from constructs import Construct
3+
4+
POWERTOOLS_BASE_NAME = "AWSLambdaPowertools"
5+
# Find latest from github.com/aws-powertools/powertools-lambda-python/releases
6+
POWERTOOLS_VER = "2.37.0"
7+
POWERTOOLS_ARN = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer"
8+
9+
10+
class SampleApp(Stack):
11+
12+
def __init__(self, scope: Construct, id_: str) -> None:
13+
super().__init__(scope, id_)
14+
15+
# Launches SAR App as CloudFormation nested stack and return Lambda Layer
16+
powertools_app = aws_sam.CfnApplication(
17+
self,
18+
f"{POWERTOOLS_BASE_NAME}Application",
19+
location={"applicationId": POWERTOOLS_ARN, "semanticVersion": POWERTOOLS_VER},
20+
)
21+
22+
powertools_layer_arn = powertools_app.get_att("Outputs.LayerVersionArn").to_string()
23+
powertools_layer_version = aws_lambda.LayerVersion.from_layer_version_arn(
24+
self,
25+
f"{POWERTOOLS_BASE_NAME}",
26+
powertools_layer_arn,
27+
)
28+
29+
aws_lambda.Function(
30+
self,
31+
"sample-app-lambda",
32+
runtime=aws_lambda.Runtime.PYTHON_3_12,
33+
function_name="sample-lambda",
34+
code=aws_lambda.Code.from_asset("lambda"),
35+
handler="hello.handler",
36+
layers=[powertools_layer_version],
37+
)

‎examples/install/sar/sam.yaml renamed to ‎examples/homepage/install/sar/sam.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
14
Resources:
25
AwsLambdaPowertoolsPythonLayer:
36
Type: AWS::Serverless::Application
@@ -9,6 +12,8 @@ Resources:
912
MyLambdaFunction:
1013
Type: AWS::Serverless::Function
1114
Properties:
12-
Layers:
13-
# fetch Layer ARN from SAR App stack output
14-
- !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn
15+
Runtime: python3.12
16+
Handler: app.lambda_handler
17+
Layers:
18+
# fetch Layer ARN from SAR App stack output
19+
- !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
Resources:
3+
PowertoolsLayerIamRole:
4+
Type: "AWS::IAM::Role"
5+
Properties:
6+
AssumeRolePolicyDocument:
7+
Version: "2012-10-17"
8+
Statement:
9+
- Effect: "Allow"
10+
Principal:
11+
Service:
12+
- "cloudformation.amazonaws.com"
13+
Action:
14+
- "sts:AssumeRole"
15+
Path: "/"
16+
17+
PowertoolsLayerIamPolicy:
18+
Type: "AWS::IAM::Policy"
19+
Properties:
20+
PolicyName: PowertoolsLambdaLayerPolicy
21+
PolicyDocument:
22+
Version: "2012-10-17"
23+
Statement:
24+
- Sid: CloudFormationTransform
25+
Effect: Allow
26+
Action: cloudformation:CreateChangeSet
27+
Resource:
28+
- arn:aws:cloudformation:us-east-1:aws:transform/Serverless-2016-10-31
29+
- Sid: GetCfnTemplate
30+
Effect: Allow
31+
Action:
32+
- serverlessrepo:CreateCloudFormationTemplate
33+
- serverlessrepo:GetCloudFormationTemplate
34+
Resource:
35+
# this is arn of the Powertools for AWS Lambda (Python) SAR app
36+
- arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
37+
- Sid: S3AccessLayer
38+
Effect: Allow
39+
Action:
40+
- s3:GetObject
41+
Resource:
42+
# AWS publishes to an external S3 bucket locked down to your account ID
43+
# The below example is us publishing Powertools for AWS Lambda (Python)
44+
# Bucket: awsserverlessrepo-changesets-plntc6bfnfj
45+
# Key: *****/arn:aws:serverlessrepo:eu-west-1:057560766410:applications-aws-lambda-powertools-python-layer-versions-1.10.2/aeeccf50-****-****-****-*********
46+
- arn:aws:s3:::awsserverlessrepo-changesets-*/*
47+
- Sid: GetLayerVersion
48+
Effect: Allow
49+
Action:
50+
- lambda:PublishLayerVersion
51+
- lambda:GetLayerVersion
52+
Resource:
53+
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-lambda-powertools-python-layer*
54+
Roles:
55+
- Ref: "PowertoolsLayerIamRole"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
service: powertools-lambda
2+
3+
provider:
4+
name: aws
5+
runtime: python3.12
6+
region: us-east-1
7+
8+
functions:
9+
powertools:
10+
handler: lambda_function.lambda_handler
11+
layers:
12+
- !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn
13+
14+
resources:
15+
- AwsLambdaPowertoolsPythonLayer:
16+
Type: AWS::Serverless::Application
17+
Properties:
18+
Location:
19+
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
20+
SemanticVersion: 2.0.0

‎examples/install/sar/terraform.tf renamed to ‎examples/homepage/install/sar/terraform.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77

88
provider "aws" {
9-
region = "us-east-1"
9+
region = "us-east-1"
1010
}
1111

1212
resource "aws_serverlessapplicationrepository_cloudformation_stack" "deploy_sar_stack" {
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from aws_cdk import (
2-
Stack,
3-
aws_lambda,
4-
Aws
5-
)
1+
from aws_cdk import Aws, Stack, aws_lambda
62
from constructs import Construct
73

4+
85
class SampleApp(Stack):
96

107
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
@@ -13,12 +10,13 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
1310
powertools_layer = aws_lambda.LayerVersion.from_layer_version_arn(
1411
self,
1512
id="lambda-powertools",
16-
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69"
13+
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69",
1714
)
18-
aws_lambda.Function(self,
19-
'sample-app-lambda',
15+
aws_lambda.Function(
16+
self,
17+
"sample-app-lambda",
2018
runtime=aws_lambda.Runtime.PYTHON_3_12,
2119
layers=[powertools_layer],
22-
code=aws_lambda.Code.from_asset('lambda'),
23-
handler='hello.handler'
20+
code=aws_lambda.Code.from_asset("lambda"),
21+
handler="hello.handler",
2422
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import json
2+
3+
import pulumi
4+
import pulumi_aws as aws
5+
6+
role = aws.iam.Role(
7+
"role",
8+
assume_role_policy=json.dumps(
9+
{
10+
"Version": "2012-10-17",
11+
"Statement": [
12+
{"Action": "sts:AssumeRole", "Principal": {"Service": "lambda.amazonaws.com"}, "Effect": "Allow"},
13+
],
14+
},
15+
),
16+
managed_policy_arns=[aws.iam.ManagedPolicy.AWS_LAMBDA_BASIC_EXECUTION_ROLE],
17+
)
18+
19+
lambda_function = aws.lambda_.Function(
20+
"function",
21+
layers=[
22+
pulumi.Output.concat(
23+
"arn:aws:lambda:",
24+
aws.get_region_output().name,
25+
":017000801446:layer:AWSLambdaPowertoolsPythonV2:69",
26+
),
27+
],
28+
tracing_config={"mode": "Active"},
29+
runtime=aws.lambda_.Runtime.PYTHON3D9,
30+
handler="index.handler",
31+
role=role.arn,
32+
architectures=["x86_64"],
33+
code=pulumi.FileArchive("lambda_function_payload.zip"),
34+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
14
Resources:
25
MyLambdaFunction:
36
Type: AWS::Serverless::Function
47
Properties:
8+
Runtime: python3.12
9+
Handler: app.lambda_handler
510
Layers:
611
- !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
service: powertools-lambda
2+
3+
provider:
4+
name: aws
5+
runtime: python3.12
6+
region: us-east-1
7+
18
functions:
2-
hello:
9+
powertools:
310
handler: lambda_function.lambda_handler
11+
architecture: arm64
412
layers:
513
- arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
terraform {
2+
required_version = "~> 1.0.5"
3+
required_providers {
4+
aws = "~> 3.50.0"
5+
}
6+
}
7+
8+
provider "aws" {
9+
region = "{region}"
10+
}
11+
12+
resource "aws_iam_role" "iam_for_lambda" {
13+
name = "iam_for_lambda"
14+
15+
assume_role_policy = <<EOF
16+
{
17+
"Version": "2012-10-17",
18+
"Statement": [
19+
{
20+
"Action": "sts:AssumeRole",
21+
"Principal": {
22+
"Service": "lambda.amazonaws.com"
23+
},
24+
"Effect": "Allow"
25+
}
26+
]
27+
}
28+
EOF
29+
}
30+
31+
resource "aws_lambda_function" "test_lambda" {
32+
filename = "lambda_function_payload.zip"
33+
function_name = "lambda_function_name"
34+
role = aws_iam_role.iam_for_lambda.arn
35+
handler = "index.test"
36+
runtime = "python3.12"
37+
layers = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69"]
38+
39+
source_code_hash = filebase64sha256("lambda_function_payload.zip")
40+
}

‎examples/install/arm64/pulumi.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎examples/install/arm64/serverless.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎examples/install/sar/cdk.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎examples/install/sar/scoped_down_iam.yaml

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎examples/install/sar/serverless.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎examples/install/x86_64/pulumi.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎examples/install/x86_64/terraform.tf

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.