Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(homepage): Change installation to CDK v2 #4351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ repos:
entry: poetry run cfn-lint
language: system
types: [yaml]
exclude: examples/homepage/install/.*?/serverless\.yml$
files: examples/.*
- repo: https://github.com/rhysd/actionlint
rev: "fd7ba3c382e13dcc0248e425b4cbc3f1185fa3ee" # v1.6.24
Expand Down
447 changes: 31 additions & 416 deletions docs/index.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/homepage/install/arm64/amplify.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create a new one with the layer
❯ amplify add function
? Select which capability you want to add: Lambda function (serverless function)
? Provide an AWS Lambda function name: <NAME-OF-FUNCTION>
? Choose the runtime that you want to use: Python
? Do you want to configure advanced settings? Yes
...
? Do you want to enable Lambda layers for this function? Yes
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69
❯ amplify push -y


# Updating an existing function and add the layer
❯ amplify update function
? Select the Lambda function you want to update test2
General information
- Name: <NAME-OF-FUNCTION>
? Which setting do you want to update? Lambda layers configuration
? Do you want to enable Lambda layers for this function? Yes
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69
? Do you want to edit the local lambda function now? No
23 changes: 23 additions & 0 deletions examples/homepage/install/arm64/cdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from aws_cdk import Aws, Stack, aws_lambda
from constructs import Construct


class SampleApp(Stack):

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

powertools_layer = aws_lambda.LayerVersion.from_layer_version_arn(
self,
id="lambda-powertools",
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69",
)
aws_lambda.Function(
self,
"sample-app-lambda",
runtime=aws_lambda.Runtime.PYTHON_3_12,
layers=[powertools_layer],
architecture=aws_lambda.Architecture.ARM_64,
code=aws_lambda.Code.from_asset("lambda"),
handler="hello.handler",
)
34 changes: 34 additions & 0 deletions examples/homepage/install/arm64/pulumi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json

import pulumi
import pulumi_aws as aws

role = aws.iam.Role(
"role",
assume_role_policy=json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{"Action": "sts:AssumeRole", "Principal": {"Service": "lambda.amazonaws.com"}, "Effect": "Allow"},
],
},
),
managed_policy_arns=[aws.iam.ManagedPolicy.AWS_LAMBDA_BASIC_EXECUTION_ROLE],
)

lambda_function = aws.lambda_.Function(
"function",
layers=[
pulumi.Output.concat(
"arn:aws:lambda:",
aws.get_region_output().name,
":017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69",
),
],
tracing_config={"mode": "Active"},
runtime=aws.lambda_.Runtime.PYTHON3D9,
handler="index.handler",
role=role.arn,
architectures=["arm64"],
code=pulumi.FileArchive("lambda_function_payload.zip"),
)
12 changes: 12 additions & 0 deletions examples/homepage/install/arm64/sam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Architectures: [arm64]
Runtime: python3.12
Handler: app.lambda_handler
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69
13 changes: 13 additions & 0 deletions examples/homepage/install/arm64/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
service: powertools-lambda

provider:
name: aws
runtime: python3.12
region: us-east-1

functions:
powertools:
handler: lambda_function.lambda_handler
architecture: arm64
layers:
- arn:aws:lambda:${aws:region}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69
41 changes: 41 additions & 0 deletions examples/homepage/install/arm64/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_version = "~> 1.0.5"
required_providers {
aws = "~> 3.50.0"
}
}

provider "aws" {
region = "{region}"
}

resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}

resource "aws_lambda_function" "test_lambda" {
filename = "lambda_function_payload.zip"
function_name = "lambda_function_name"
role = aws_iam_role.iam_for_lambda.arn
handler = "index.test"
runtime = "python3.9"
layers = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:69"]
architectures = ["arm64"]

source_code_hash = filebase64sha256("lambda_function_payload.zip")
}
37 changes: 37 additions & 0 deletions examples/homepage/install/sar/cdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from aws_cdk import Stack, aws_lambda, aws_sam
from constructs import Construct

POWERTOOLS_BASE_NAME = "AWSLambdaPowertools"
# Find latest from github.com/aws-powertools/powertools-lambda-python/releases
POWERTOOLS_VER = "2.37.0"
POWERTOOLS_ARN = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer"


class SampleApp(Stack):

def __init__(self, scope: Construct, id_: str) -> None:
super().__init__(scope, id_)

# Launches SAR App as CloudFormation nested stack and return Lambda Layer
powertools_app = aws_sam.CfnApplication(
self,
f"{POWERTOOLS_BASE_NAME}Application",
location={"applicationId": POWERTOOLS_ARN, "semanticVersion": POWERTOOLS_VER},
)

powertools_layer_arn = powertools_app.get_att("Outputs.LayerVersionArn").to_string()
powertools_layer_version = aws_lambda.LayerVersion.from_layer_version_arn(
self,
f"{POWERTOOLS_BASE_NAME}",
powertools_layer_arn,
)

aws_lambda.Function(
self,
"sample-app-lambda",
runtime=aws_lambda.Runtime.PYTHON_3_12,
function_name="sample-lambda",
code=aws_lambda.Code.from_asset("lambda"),
handler="hello.handler",
layers=[powertools_layer_version],
)
19 changes: 19 additions & 0 deletions examples/homepage/install/sar/sam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
AwsLambdaPowertoolsPythonLayer:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
SemanticVersion: 2.0.0 # change to latest semantic version available in SAR

MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.12
Handler: app.lambda_handler
Layers:
# fetch Layer ARN from SAR App stack output
- !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn
55 changes: 55 additions & 0 deletions examples/homepage/install/sar/scoped_down_iam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
AWSTemplateFormatVersion: "2010-09-09"
Resources:
PowertoolsLayerIamRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "cloudformation.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"

PowertoolsLayerIamPolicy:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: PowertoolsLambdaLayerPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: CloudFormationTransform
Effect: Allow
Action: cloudformation:CreateChangeSet
Resource:
- arn:aws:cloudformation:us-east-1:aws:transform/Serverless-2016-10-31
- Sid: GetCfnTemplate
Effect: Allow
Action:
- serverlessrepo:CreateCloudFormationTemplate
- serverlessrepo:GetCloudFormationTemplate
Resource:
# this is arn of the Powertools for AWS Lambda (Python) SAR app
- arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
- Sid: S3AccessLayer
Effect: Allow
Action:
- s3:GetObject
Resource:
# AWS publishes to an external S3 bucket locked down to your account ID
# The below example is us publishing Powertools for AWS Lambda (Python)
# Bucket: awsserverlessrepo-changesets-plntc6bfnfj
# Key: *****/arn:aws:serverlessrepo:eu-west-1:057560766410:applications-aws-lambda-powertools-python-layer-versions-1.10.2/aeeccf50-****-****-****-*********
- arn:aws:s3:::awsserverlessrepo-changesets-*/*
- Sid: GetLayerVersion
Effect: Allow
Action:
- lambda:PublishLayerVersion
- lambda:GetLayerVersion
Resource:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:aws-lambda-powertools-python-layer*
Roles:
- Ref: "PowertoolsLayerIamRole"
20 changes: 20 additions & 0 deletions examples/homepage/install/sar/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
service: powertools-lambda

provider:
name: aws
runtime: python3.12
region: us-east-1

functions:
powertools:
handler: lambda_function.lambda_handler
layers:
- !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn

resources:
- AwsLambdaPowertoolsPythonLayer:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer
SemanticVersion: 2.0.0
41 changes: 41 additions & 0 deletions examples/homepage/install/sar/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_version = "~> 0.13"
required_providers {
aws = "~> 3.50.0"
}
}

provider "aws" {
region = "us-east-1"
}

resource "aws_serverlessapplicationrepository_cloudformation_stack" "deploy_sar_stack" {
name = "aws-lambda-powertools-python-layer"

application_id = data.aws_serverlessapplicationrepository_application.sar_app.application_id
semantic_version = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version
capabilities = [
"CAPABILITY_IAM",
"CAPABILITY_NAMED_IAM"
]
}

data "aws_serverlessapplicationrepository_application" "sar_app" {
application_id = "arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer"
semantic_version = var.aws_powertools_version
}

variable "aws_powertools_version" {
type = string
default = "2.0.0"
description = "The Powertools for AWS Lambda (Python) release version"
}

output "deployed_powertools_sar_version" {
value = data.aws_serverlessapplicationrepository_application.sar_app.semantic_version
}

# Fetch Powertools for AWS Lambda (Python) Layer ARN from deployed SAR App
output "aws_lambda_powertools_layer_arn" {
value = aws_serverlessapplicationrepository_cloudformation_stack.deploy_sar_stack.outputs.LayerVersionArn
}
21 changes: 21 additions & 0 deletions examples/homepage/install/x86_64/amplify.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create a new one with the layer
❯ amplify add function
? Select which capability you want to add: Lambda function (serverless function)
? Provide an AWS Lambda function name: <NAME-OF-FUNCTION>
? Choose the runtime that you want to use: Python
? Do you want to configure advanced settings? Yes
...
? Do you want to enable Lambda layers for this function? Yes
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:69
❯ amplify push -y


# Updating an existing function and add the layer
❯ amplify update function
? Select the Lambda function you want to update test2
General information
- Name: <NAME-OF-FUNCTION>
? Which setting do you want to update? Lambda layers configuration
? Do you want to enable Lambda layers for this function? Yes
? Enter up to 5 existing Lambda layer ARNs (comma-separated): arn:aws:lambda:eu-central-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:69
? Do you want to edit the local lambda function now? No
22 changes: 22 additions & 0 deletions examples/homepage/install/x86_64/cdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from aws_cdk import Aws, Stack, aws_lambda
from constructs import Construct


class SampleApp(Stack):

def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

powertools_layer = aws_lambda.LayerVersion.from_layer_version_arn(
self,
id="lambda-powertools",
layer_version_arn=f"arn:aws:lambda:{Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2:69",
)
aws_lambda.Function(
self,
"sample-app-lambda",
runtime=aws_lambda.Runtime.PYTHON_3_12,
layers=[powertools_layer],
code=aws_lambda.Code.from_asset("lambda"),
handler="hello.handler",
)
Loading