From 47505dc4493239327ea75904225c81fab0a0cf2c Mon Sep 17 00:00:00 2001 From: Fokko Bucys Date: Mon, 10 Jan 2022 13:22:39 +0000 Subject: [PATCH 1/2] docs(install): Improved CDK usage guidance The way how the AWS Data Wrangler Layer can used within CDK and SAR is improved. Resolves: #1097 --- docs/source/install.rst | 58 ++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/docs/source/install.rst b/docs/source/install.rst index b96adabd3..58ca79adc 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -79,21 +79,61 @@ Serverless Application Repository (SAR) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AWS Data Wrangler layers are also available in the `AWS Serverless Application Repository `_ (SAR). +The SAR App can be used to deploy a CloudFormation stack with a copy of the Lambda layer in your own AWS account and region. This option provides furthermore +the possibility to use semantic versions instead of Lambda layer versions. -Here is an example of how to create the Lambda layer in your CDK app: +.. list-table:: AWS Data Wrangler Layer Apps + :widths: 25 25 50 + :header-rows: 1 + + * - App + - ARN + - Description + * - aws-data-wrangler-layer-py3-7 + - arn:aws:serverlessrepo:us-east-1:336392948345:applications/aws-data-wrangler-layer-py3-7 + - Layer for ``Python 3.7.x`` runtimes + * - aws-data-wrangler-layer-py3-8 + - arn:aws:serverlessrepo:us-east-1:336392948345:applications/aws-data-wrangler-layer-py3-8 + - Layer for ``Python 3.8.x`` runtimes + * - aws-data-wrangler-layer-py3-9 + - arn:aws:serverlessrepo:us-east-1:336392948345:applications/aws-data-wrangler-layer-py3-9 + - Layer for ``Python 3.9.x`` runtimes + +Here is an example of how to create and use the AWS Data Wrangler Lambda layer in your CDK app: .. code-block:: python + + from aws_cdk import core, aws_sam as sam, aws_lambda - CfnApplication( - self, - "wrangler-layer", - location=CfnApplication.ApplicationLocationProperty( - application_id="arn:aws:serverlessrepo:us-east-1:336392948345:applications/aws-data-wrangler-layer-py3-8", - semantic_version="2.12.0", - ), - ) + class DataWranglerApp(core.Construct): + def __init__(self, scope: core.Construct, id_: str): + super.__init__(scope,id) + wrangler_layer = sam.CfnApplication( + self, + "wrangler-layer", + location=CfnApplication.ApplicationLocationProperty( + application_id="arn:aws:serverlessrepo:us-east-1:336392948345:applications/aws-data-wrangler-layer-py3-8", + semantic_version="2.13.0", # Get the latest version from https://github.com/awslabs/aws-data-wrangler/releases + ), + ) + + wrangler_layer_arn = wrangler_layer.get_att("Outputs.WranglerLayer38Arn").to_string() + wrangler_layer_version = aws_lambda.LayerVersion.from_layer_version_arn(self, "AWSDataWranglerLayer", wrangler_layer_arn) + + aws_lambda.Function(self, + "sample-wrangler-function", + runtime=aws_lambda.Runtime.PYHTON_3_8, + function_name="sample-wrangler-lambda-function", + code=aws_lambda.Code.asset("./src/wrangler-lambda"), + handler='lambda_function.lambda_handler', + layers=[wrangler_layer_version] + ) + +.. note:: The attribute ``Outputs.WranglerLayer38Arn`` is dependent to the layer for the Python version you want to use. Remind to change + ``38`` to ``37`` or ``39`` if using a layer for ``Python 3.7.x`` or ``Python 3.9.x`` instead of ``Python 3.8.x``. + AWS Glue Python Shell Jobs -------------------------- From fe02b869395b4a679ec3583c5e552f4aae0090d5 Mon Sep 17 00:00:00 2001 From: Abdel Jaidi Date: Tue, 11 Jan 2022 16:55:38 +0000 Subject: [PATCH 2/2] Minor fixes --- docs/source/install.rst | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/source/install.rst b/docs/source/install.rst index 58ca79adc..b85afa999 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -79,8 +79,9 @@ Serverless Application Repository (SAR) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AWS Data Wrangler layers are also available in the `AWS Serverless Application Repository `_ (SAR). -The SAR App can be used to deploy a CloudFormation stack with a copy of the Lambda layer in your own AWS account and region. This option provides furthermore -the possibility to use semantic versions instead of Lambda layer versions. + +The app deploys the Lambda layer version in your own AWS account and region via a CloudFormation stack. +This option provides the ability to use semantic versions (i.e. library version) instead of Lambda layer versions. .. list-table:: AWS Data Wrangler Layer Apps :widths: 25 25 50 @@ -109,7 +110,6 @@ Here is an example of how to create and use the AWS Data Wrangler Lambda layer i def __init__(self, scope: core.Construct, id_: str): super.__init__(scope,id) - wrangler_layer = sam.CfnApplication( self, "wrangler-layer", @@ -120,20 +120,18 @@ Here is an example of how to create and use the AWS Data Wrangler Lambda layer i ) wrangler_layer_arn = wrangler_layer.get_att("Outputs.WranglerLayer38Arn").to_string() - wrangler_layer_version = aws_lambda.LayerVersion.from_layer_version_arn(self, "AWSDataWranglerLayer", wrangler_layer_arn) + wrangler_layer_version = aws_lambda.LayerVersion.from_layer_version_arn(self, "wrangler-layer-version", wrangler_layer_arn) - aws_lambda.Function(self, - "sample-wrangler-function", - runtime=aws_lambda.Runtime.PYHTON_3_8, + aws_lambda.Function( + self, + "wrangler-function", + runtime=aws_lambda.Runtime.PYTHON_3_8, function_name="sample-wrangler-lambda-function", code=aws_lambda.Code.asset("./src/wrangler-lambda"), handler='lambda_function.lambda_handler', layers=[wrangler_layer_version] ) -.. note:: The attribute ``Outputs.WranglerLayer38Arn`` is dependent to the layer for the Python version you want to use. Remind to change - ``38`` to ``37`` or ``39`` if using a layer for ``Python 3.7.x`` or ``Python 3.9.x`` instead of ``Python 3.8.x``. - AWS Glue Python Shell Jobs --------------------------