diff --git a/packages/@aws-cdk/lambda-layer-awscli/README.md b/packages/@aws-cdk/lambda-layer-awscli/README.md index e36677c222de0..c902510290dde 100644 --- a/packages/@aws-cdk/lambda-layer-awscli/README.md +++ b/packages/@aws-cdk/lambda-layer-awscli/README.md @@ -12,6 +12,8 @@ This module exports a single class called `AwsCliLayer` which is a `lambda.Layer` that bundles the AWS CLI. +Any Lambda Function that uses this layer must use a Python 3.x runtime. + Usage: ```ts diff --git a/packages/@aws-cdk/lambda-layer-awscli/awscli.version b/packages/@aws-cdk/lambda-layer-awscli/awscli.version deleted file mode 100644 index e0a2d9dda44ac..0000000000000 --- a/packages/@aws-cdk/lambda-layer-awscli/awscli.version +++ /dev/null @@ -1 +0,0 @@ -1.22.46 diff --git a/packages/@aws-cdk/lambda-layer-awscli/build-tools/bump-awscli-version.sh b/packages/@aws-cdk/lambda-layer-awscli/build-tools/bump-awscli-version.sh deleted file mode 100755 index e81df6f725c73..0000000000000 --- a/packages/@aws-cdk/lambda-layer-awscli/build-tools/bump-awscli-version.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -eu -scriptdir=$(cd $(dirname $0) && pwd) - -package=awscli -tmpfile=_pip.json - -curl -LsSf https://pypi.org/pypi/awscli/json > $tmpfile -trap "rm $tmpfile" EXIT -version=$(node -p "require('./${tmpfile}').info.version") - -if [[ $version != 1.* ]]; then - echo "Expected version 1.*, got ${version}" >&2 - exit 1 -fi - -echo "AWS CLI is currently at ${version}" - -echo $version > $scriptdir/../awscli.version diff --git a/packages/@aws-cdk/lambda-layer-awscli/layer/Dockerfile b/packages/@aws-cdk/lambda-layer-awscli/layer/Dockerfile index 92a513042a630..ef5c7c91d65c6 100644 --- a/packages/@aws-cdk/lambda-layer-awscli/layer/Dockerfile +++ b/packages/@aws-cdk/lambda-layer-awscli/layer/Dockerfile @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/provided:latest +FROM public.ecr.aws/sam/build-python3.7 USER root RUN mkdir -p /opt @@ -9,27 +9,19 @@ WORKDIR /tmp # RUN yum update -y \ - && yum install -y zip unzip wget tar gzip python3 + && yum install -y zip unzip wget tar gzip # # aws cli # -ARG AWSCLI_VERSION=0.0.0 - -RUN curl https://s3.amazonaws.com/aws-cli/awscli-bundle-${AWSCLI_VERSION}.zip -o awscli-bundle.zip -RUN unzip awscli-bundle.zip -RUN python3 ./awscli-bundle/install -i /opt/awscli -b /opt/awscli/aws +COPY requirements.txt ./ +RUN python -m pip install -r requirements.txt -t /opt/awscli # organize for self-contained usage -RUN mv /opt/awscli /opt/awscli.tmp -RUN pyver=$(python3 -c 'import sys; v = sys.version_info; print(f"{v[0]}.{v[1]}")') && \ - mv /opt/awscli.tmp/lib/python${pyver}/site-packages /opt/awscli -RUN mv /opt/awscli.tmp/bin /opt/awscli/bin -RUN mv /opt/awscli/bin/aws /opt/awscli +RUN mv /opt/awscli/bin/aws /opt/awscli # cleanup -RUN rm -fr /opt/awscli.tmp RUN rm -rf \ /opt/awscli/pip* \ /opt/awscli/setuptools* \ diff --git a/packages/@aws-cdk/lambda-layer-awscli/layer/build.sh b/packages/@aws-cdk/lambda-layer-awscli/layer/build.sh index 99fee83d1be54..a7c13263ebdce 100755 --- a/packages/@aws-cdk/lambda-layer-awscli/layer/build.sh +++ b/packages/@aws-cdk/lambda-layer-awscli/layer/build.sh @@ -3,13 +3,11 @@ set -euo pipefail cd $(dirname $0) -version=$(cat ../awscli.version) - -echo ">> Building AWS Lambda layer inside a docker image for CLI version ${version}..." +echo ">> Building AWS Lambda layer inside a docker image..." TAG='aws-lambda-layer' -docker build -t ${TAG} . --build-arg AWSCLI_VERSION=${version} +docker build -t ${TAG} . echo ">> Extrating layer.zip from the build container..." CONTAINER=$(docker run -d ${TAG} false) diff --git a/packages/@aws-cdk/lambda-layer-awscli/layer/requirements.txt b/packages/@aws-cdk/lambda-layer-awscli/layer/requirements.txt new file mode 100644 index 0000000000000..341ac4e870808 --- /dev/null +++ b/packages/@aws-cdk/lambda-layer-awscli/layer/requirements.txt @@ -0,0 +1 @@ +awscli==1.22.46 diff --git a/packages/@aws-cdk/lambda-layer-awscli/lib/awscli-layer.ts b/packages/@aws-cdk/lambda-layer-awscli/lib/awscli-layer.ts index 525babcac82f3..9bc2584fda3ad 100644 --- a/packages/@aws-cdk/lambda-layer-awscli/lib/awscli-layer.ts +++ b/packages/@aws-cdk/lambda-layer-awscli/lib/awscli-layer.ts @@ -1,7 +1,6 @@ -import * as crypto from 'crypto'; -import * as fs from 'fs'; import * as path from 'path'; import * as lambda from '@aws-cdk/aws-lambda'; +import { FileSystem } from '@aws-cdk/core'; import { Construct } from 'constructs'; /** @@ -11,17 +10,10 @@ export class AwsCliLayer extends lambda.LayerVersion { constructor(scope: Construct, id: string) { super(scope, id, { code: lambda.Code.fromAsset(path.join(__dirname, 'layer.zip'), { - // we hash the Dockerfile (it contains the tools versions) because hashing the zip is non-deterministic - assetHash: hashFile(path.join(__dirname, '..', 'layer', 'Dockerfile')), + // we hash the layer directory (it contains the tools versions and Dockerfile) because hashing the zip is non-deterministic + assetHash: FileSystem.fingerprint(path.join(__dirname, '../layer')), }), description: '/opt/awscli/aws', }); } } - -function hashFile(fileName: string) { - return crypto - .createHash('sha256') - .update(fs.readFileSync(fileName)) - .digest('hex'); -} \ No newline at end of file diff --git a/packages/@aws-cdk/lambda-layer-awscli/package.json b/packages/@aws-cdk/lambda-layer-awscli/package.json index cf5a3d857f5b3..72e500cd130b2 100644 --- a/packages/@aws-cdk/lambda-layer-awscli/package.json +++ b/packages/@aws-cdk/lambda-layer-awscli/package.json @@ -74,6 +74,7 @@ "license": "Apache-2.0", "devDependencies": { "@aws-cdk/assertions": "0.0.0", + "@aws-cdk/custom-resources": "0.0.0", "@aws-cdk/cdk-build-tools": "0.0.0", "@aws-cdk/cdk-integ-tools": "0.0.0", "@aws-cdk/pkglint": "0.0.0", diff --git a/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.expected.json b/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.expected.json new file mode 100644 index 0000000000000..d37e67106e0cf --- /dev/null +++ b/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.expected.json @@ -0,0 +1,773 @@ +{ + "Resources": { + "AwsCliLayerF44AAF94": { + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": { + "Ref": "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3S3BucketD774C319" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3S3VersionKey9C5C53B3" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3S3VersionKey9C5C53B3" + } + ] + } + ] + } + ] + ] + } + }, + "Description": "/opt/awscli/aws" + } + }, + "Lambdapython36ServiceRole658256F3": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Lambdapython36B64E8A5D": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3Bucket1DD21439" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Lambdapython36ServiceRole658256F3", + "Arn" + ] + }, + "Handler": "index.handler", + "Layers": [ + { + "Ref": "AwsCliLayerF44AAF94" + } + ], + "MemorySize": 512, + "Runtime": "python3.6", + "Timeout": 30 + }, + "DependsOn": [ + "Lambdapython36ServiceRole658256F3" + ] + }, + "Providerpython36frameworkonEventServiceRole0B176429": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Providerpython36frameworkonEventServiceRoleDefaultPolicy414F3608": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "Lambdapython36B64E8A5D", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "Providerpython36frameworkonEventServiceRoleDefaultPolicy414F3608", + "Roles": [ + { + "Ref": "Providerpython36frameworkonEventServiceRole0B176429" + } + ] + } + }, + "Providerpython36frameworkonEventA3B6DD44": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3BucketBA45D90E" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Providerpython36frameworkonEventServiceRole0B176429", + "Arn" + ] + }, + "Description": "AWS CDK resource provider framework - onEvent (lambda-layer-awscli-integ-stack/Providerpython3.6)", + "Environment": { + "Variables": { + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "Lambdapython36B64E8A5D", + "Arn" + ] + } + } + }, + "Handler": "framework.onEvent", + "Runtime": "nodejs12.x", + "Timeout": 900 + }, + "DependsOn": [ + "Providerpython36frameworkonEventServiceRoleDefaultPolicy414F3608", + "Providerpython36frameworkonEventServiceRole0B176429" + ] + }, + "CustomResourcepython36": { + "Type": "AWS::CloudFormation::CustomResource", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "Providerpython36frameworkonEventA3B6DD44", + "Arn" + ] + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "Lambdapython37ServiceRoleB5A704D4": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Lambdapython3780349E0A": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3Bucket1DD21439" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Lambdapython37ServiceRoleB5A704D4", + "Arn" + ] + }, + "Handler": "index.handler", + "Layers": [ + { + "Ref": "AwsCliLayerF44AAF94" + } + ], + "MemorySize": 512, + "Runtime": "python3.7", + "Timeout": 30 + }, + "DependsOn": [ + "Lambdapython37ServiceRoleB5A704D4" + ] + }, + "Providerpython37frameworkonEventServiceRole9EA6B2B0": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Providerpython37frameworkonEventServiceRoleDefaultPolicyA9099DC2": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "Lambdapython3780349E0A", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "Providerpython37frameworkonEventServiceRoleDefaultPolicyA9099DC2", + "Roles": [ + { + "Ref": "Providerpython37frameworkonEventServiceRole9EA6B2B0" + } + ] + } + }, + "Providerpython37frameworkonEvent3AA4F69E": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3BucketBA45D90E" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Providerpython37frameworkonEventServiceRole9EA6B2B0", + "Arn" + ] + }, + "Description": "AWS CDK resource provider framework - onEvent (lambda-layer-awscli-integ-stack/Providerpython3.7)", + "Environment": { + "Variables": { + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "Lambdapython3780349E0A", + "Arn" + ] + } + } + }, + "Handler": "framework.onEvent", + "Runtime": "nodejs12.x", + "Timeout": 900 + }, + "DependsOn": [ + "Providerpython37frameworkonEventServiceRoleDefaultPolicyA9099DC2", + "Providerpython37frameworkonEventServiceRole9EA6B2B0" + ] + }, + "CustomResourcepython37": { + "Type": "AWS::CloudFormation::CustomResource", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "Providerpython37frameworkonEvent3AA4F69E", + "Arn" + ] + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "Lambdapython39ServiceRoleE2CFED77": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Lambdapython39426A0480": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3Bucket1DD21439" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Lambdapython39ServiceRoleE2CFED77", + "Arn" + ] + }, + "Handler": "index.handler", + "Layers": [ + { + "Ref": "AwsCliLayerF44AAF94" + } + ], + "MemorySize": 512, + "Runtime": "python3.9", + "Timeout": 30 + }, + "DependsOn": [ + "Lambdapython39ServiceRoleE2CFED77" + ] + }, + "Providerpython39frameworkonEventServiceRoleA299F5C1": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Providerpython39frameworkonEventServiceRoleDefaultPolicy16A4767C": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "Lambdapython39426A0480", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "Providerpython39frameworkonEventServiceRoleDefaultPolicy16A4767C", + "Roles": [ + { + "Ref": "Providerpython39frameworkonEventServiceRoleA299F5C1" + } + ] + } + }, + "Providerpython39frameworkonEvent00AFA742": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3BucketBA45D90E" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "Providerpython39frameworkonEventServiceRoleA299F5C1", + "Arn" + ] + }, + "Description": "AWS CDK resource provider framework - onEvent (lambda-layer-awscli-integ-stack/Providerpython3.9)", + "Environment": { + "Variables": { + "USER_ON_EVENT_FUNCTION_ARN": { + "Fn::GetAtt": [ + "Lambdapython39426A0480", + "Arn" + ] + } + } + }, + "Handler": "framework.onEvent", + "Runtime": "nodejs12.x", + "Timeout": 900 + }, + "DependsOn": [ + "Providerpython39frameworkonEventServiceRoleDefaultPolicy16A4767C", + "Providerpython39frameworkonEventServiceRoleA299F5C1" + ] + }, + "CustomResourcepython39": { + "Type": "AWS::CloudFormation::CustomResource", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "Providerpython39frameworkonEvent00AFA742", + "Arn" + ] + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "Parameters": { + "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3S3BucketD774C319": { + "Type": "String", + "Description": "S3 bucket for asset \"ba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3\"" + }, + "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3S3VersionKey9C5C53B3": { + "Type": "String", + "Description": "S3 key for asset version \"ba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3\"" + }, + "AssetParametersba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3ArtifactHash4F540915": { + "Type": "String", + "Description": "Artifact hash for asset \"ba23ea22aa357b771a4ebc95be163f8848dafee07daf2333380d3b890472d1f3\"" + }, + "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3Bucket1DD21439": { + "Type": "String", + "Description": "S3 bucket for asset \"5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48\"" + }, + "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48S3VersionKey77F71A63": { + "Type": "String", + "Description": "S3 key for asset version \"5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48\"" + }, + "AssetParameters5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48ArtifactHashA6792482": { + "Type": "String", + "Description": "Artifact hash for asset \"5dff6208ccd5fb196bb0354fd6e47faa8431a789e6125d20386586fef761ed48\"" + }, + "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3BucketBA45D90E": { + "Type": "String", + "Description": "S3 bucket for asset \"733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8c\"" + }, + "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cS3VersionKey1021C50F": { + "Type": "String", + "Description": "S3 key for asset version \"733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8c\"" + }, + "AssetParameters733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8cArtifactHash371618FE": { + "Type": "String", + "Description": "Artifact hash for asset \"733a1180c316ce99003dfcfd7bd70d8039134b3fbac69643f144aceea90d6b8c\"" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.ts b/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.ts new file mode 100644 index 0000000000000..a34009c289f5c --- /dev/null +++ b/packages/@aws-cdk/lambda-layer-awscli/test/integ.awscli-layer.ts @@ -0,0 +1,40 @@ +import * as path from 'path'; +import * as lambda from '@aws-cdk/aws-lambda'; +import * as cdk from '@aws-cdk/core'; +import * as cr from '@aws-cdk/custom-resources'; + +import { AwsCliLayer } from '../lib'; + +/** + * Test verifies that AWS CLI is invoked successfully inside Lambda runtime. + */ + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'lambda-layer-awscli-integ-stack'); +const layer = new AwsCliLayer(stack, 'AwsCliLayer'); + +const runtimes = [ + lambda.Runtime.PYTHON_3_6, + lambda.Runtime.PYTHON_3_7, + lambda.Runtime.PYTHON_3_9, +]; + +for (const runtime of runtimes) { + const provider = new cr.Provider(stack, `Provider${runtime.name}`, { + onEventHandler: new lambda.Function(stack, `Lambda$${runtime.name}`, { + code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')), + handler: 'index.handler', + runtime: runtime, + layers: [layer], + memorySize: 512, + timeout: cdk.Duration.seconds(30), + }), + }); + + new cdk.CustomResource(stack, `CustomResource${runtime.name}`, { + serviceToken: provider.serviceToken, + }); +} + +app.synth(); diff --git a/packages/@aws-cdk/lambda-layer-awscli/test/lambda-handler/index.py b/packages/@aws-cdk/lambda-layer-awscli/test/lambda-handler/index.py new file mode 100644 index 0000000000000..dafef9f351903 --- /dev/null +++ b/packages/@aws-cdk/lambda-layer-awscli/test/lambda-handler/index.py @@ -0,0 +1,5 @@ +import subprocess + +def handler(event, context): + subprocess.check_call(["/opt/awscli/aws", "--version"]) + return