diff --git a/.gitignore b/.gitignore index 1d6ae12ce76eb..d8b560ceb8ac9 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ cdk.context.json .cdk.staging/ cdk.out/ *.tabl.json +cdk-integ.out.*/ # Yarn error log yarn-error.log diff --git a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/cdk.out b/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/cdk.out deleted file mode 100644 index 8ecc185e9dbee..0000000000000 --- a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/cdk.out +++ /dev/null @@ -1 +0,0 @@ -{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.assets.json b/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.assets.json deleted file mode 100644 index 981e7b2f4cbc4..0000000000000 --- a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.assets.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "21.0.0", - "files": { - "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232": { - "source": { - "path": "/home/marcio/marcio/aws-cdk/packages/@aws-cdk/aws-lambda/test/my-lambda-handler", - "packaging": "zip" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232.zip", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - }, - "b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847": { - "source": { - "path": "lambda-test-assets.template.json", - "packaging": "file" - }, - "destinations": { - "current_account-current_region": { - "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847.json", - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" - } - } - } - }, - "dockerImages": {} -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.template.json b/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.template.json deleted file mode 100644 index 4bf977885b091..0000000000000 --- a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/lambda-test-assets.template.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "Resources": { - "MyLambdaServiceRole4539ECB6": { - "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" - ] - ] - } - ] - } - }, - "MyLambdaCCE802FB": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" - }, - "S3Key": "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyLambdaServiceRole4539ECB6", - "Arn" - ] - }, - "Handler": "index.main", - "Runtime": "python3.9" - }, - "DependsOn": [ - "MyLambdaServiceRole4539ECB6" - ] - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/manifest.json b/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/manifest.json deleted file mode 100644 index d517f7fd89f45..0000000000000 --- a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/manifest.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "version": "21.0.0", - "artifacts": { - "Tree": { - "type": "cdk:tree", - "properties": { - "file": "tree.json" - } - }, - "lambda-test-assets.assets": { - "type": "cdk:asset-manifest", - "properties": { - "file": "lambda-test-assets.assets.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "lambda-test-assets": { - "type": "aws:cloudformation:stack", - "environment": "aws://unknown-account/unknown-region", - "properties": { - "templateFile": "lambda-test-assets.template.json", - "validateOnSynth": false, - "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", - "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847.json", - "requiresBootstrapStackVersion": 6, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", - "additionalDependencies": [ - "lambda-test-assets.assets" - ], - "lookupRole": { - "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", - "requiresBootstrapStackVersion": 8, - "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" - } - }, - "dependencies": [ - "lambda-test-assets.assets" - ], - "metadata": { - "/lambda-test-assets/MyLambda/ServiceRole/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "MyLambdaServiceRole4539ECB6" - } - ], - "/lambda-test-assets/MyLambda/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "MyLambdaCCE802FB" - } - ], - "/lambda-test-assets/BootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" - } - ], - "/lambda-test-assets/CheckBootstrapVersion": [ - { - "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" - } - ] - }, - "displayName": "lambda-test-assets" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/tree.json b/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/tree.json deleted file mode 100644 index b16b292afcec8..0000000000000 --- a/packages/@aws-cdk/aws-lambda/test/cdk-integ.out/tree.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "version": "tree-0.1", - "tree": { - "id": "App", - "path": "", - "children": { - "Tree": { - "id": "Tree", - "path": "Tree", - "constructInfo": { - "fqn": "constructs.Construct", - "version": "10.1.92" - } - }, - "lambda-test-assets": { - "id": "lambda-test-assets", - "path": "lambda-test-assets", - "children": { - "MyLambda": { - "id": "MyLambda", - "path": "lambda-test-assets/MyLambda", - "children": { - "ServiceRole": { - "id": "ServiceRole", - "path": "lambda-test-assets/MyLambda/ServiceRole", - "children": { - "Resource": { - "id": "Resource", - "path": "lambda-test-assets/MyLambda/ServiceRole/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::IAM::Role", - "aws:cdk:cloudformation:props": { - "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" - ] - ] - } - ] - } - }, - "constructInfo": { - "fqn": "@aws-cdk/aws-iam.CfnRole", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/aws-iam.Role", - "version": "0.0.0" - } - }, - "Code": { - "id": "Code", - "path": "lambda-test-assets/MyLambda/Code", - "children": { - "Stage": { - "id": "Stage", - "path": "lambda-test-assets/MyLambda/Code/Stage", - "constructInfo": { - "fqn": "@aws-cdk/core.AssetStaging", - "version": "0.0.0" - } - }, - "AssetBucket": { - "id": "AssetBucket", - "path": "lambda-test-assets/MyLambda/Code/AssetBucket", - "constructInfo": { - "fqn": "@aws-cdk/aws-s3.BucketBase", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/aws-s3-assets.Asset", - "version": "0.0.0" - } - }, - "Resource": { - "id": "Resource", - "path": "lambda-test-assets/MyLambda/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::Lambda::Function", - "aws:cdk:cloudformation:props": { - "code": { - "s3Bucket": { - "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" - }, - "s3Key": "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232.zip" - }, - "role": { - "Fn::GetAtt": [ - "MyLambdaServiceRole4539ECB6", - "Arn" - ] - }, - "handler": "index.main", - "runtime": "python3.9" - } - }, - "constructInfo": { - "fqn": "@aws-cdk/aws-lambda.CfnFunction", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/aws-lambda.Function", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/core.Stack", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "@aws-cdk/core.App", - "version": "0.0.0" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/.gitignore b/packages/@aws-cdk/integ-runner/.gitignore index b342e458d9855..ee935e08d323d 100644 --- a/packages/@aws-cdk/integ-runner/.gitignore +++ b/packages/@aws-cdk/integ-runner/.gitignore @@ -27,7 +27,11 @@ junit.xml # Ignore this symlink, we recreate it at test time test/test-archive-follow/data/linked +# These files are needed for unit tests +!test/test-data/cdk-integ.out*/ + !**/*.snapshot/**/asset.*/*.js !**/*.snapshot/**/asset.*/*.d.ts !**/*.snapshot/**/asset.*/** + diff --git a/packages/@aws-cdk/pipelines/test/cdk-integ.out.pipeline-with-asset-variables/asset.60767da3831353fede3cfe92efef10580a600592dec8ccbb06c051e95b9c1b26/index.ts b/packages/@aws-cdk/pipelines/test/cdk-integ.out.pipeline-with-asset-variables/asset.60767da3831353fede3cfe92efef10580a600592dec8ccbb06c051e95b9c1b26/index.ts deleted file mode 100644 index 2459d44ab1d18..0000000000000 --- a/packages/@aws-cdk/pipelines/test/cdk-integ.out.pipeline-with-asset-variables/asset.60767da3831353fede3cfe92efef10580a600592dec8ccbb06c051e95b9c1b26/index.ts +++ /dev/null @@ -1,82 +0,0 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { S3 } from 'aws-sdk'; - -const AUTO_DELETE_OBJECTS_TAG = 'aws-cdk:auto-delete-objects'; - -const s3 = new S3(); - -export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) { - switch (event.RequestType) { - case 'Create': - return; - case 'Update': - return onUpdate(event); - case 'Delete': - return onDelete(event.ResourceProperties?.BucketName); - } -} - -async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) { - const updateEvent = event as AWSLambda.CloudFormationCustomResourceUpdateEvent; - const oldBucketName = updateEvent.OldResourceProperties?.BucketName; - const newBucketName = updateEvent.ResourceProperties?.BucketName; - const bucketNameHasChanged = newBucketName != null && oldBucketName != null && newBucketName !== oldBucketName; - - /* If the name of the bucket has changed, CloudFormation will try to delete the bucket - and create a new one with the new name. So we have to delete the contents of the - bucket so that this operation does not fail. */ - if (bucketNameHasChanged) { - return onDelete(oldBucketName); - } -} - -/** - * Recursively delete all items in the bucket - * - * @param bucketName the bucket name - */ -async function emptyBucket(bucketName: string) { - const listedObjects = await s3.listObjectVersions({ Bucket: bucketName }).promise(); - const contents = [...listedObjects.Versions ?? [], ...listedObjects.DeleteMarkers ?? []]; - if (contents.length === 0) { - return; - } - - const records = contents.map((record: any) => ({ Key: record.Key, VersionId: record.VersionId })); - await s3.deleteObjects({ Bucket: bucketName, Delete: { Objects: records } }).promise(); - - if (listedObjects?.IsTruncated) { - await emptyBucket(bucketName); - } -} - -async function onDelete(bucketName?: string) { - if (!bucketName) { - throw new Error('No BucketName was provided.'); - } - if (!await isBucketTaggedForDeletion(bucketName)) { - process.stdout.write(`Bucket does not have '${AUTO_DELETE_OBJECTS_TAG}' tag, skipping cleaning.\n`); - return; - } - try { - await emptyBucket(bucketName); - } catch (e) { - if (e.code !== 'NoSuchBucket') { - throw e; - } - // Bucket doesn't exist. Ignoring - } -} - -/** - * The bucket will only be tagged for deletion if it's being deleted in the same - * deployment as this Custom Resource. - * - * If the Custom Resource is every deleted before the bucket, it must be because - * `autoDeleteObjects` has been switched to false, in which case the tag would have - * been removed before we get to this Delete event. - */ -async function isBucketTaggedForDeletion(bucketName: string) { - const response = await s3.getBucketTagging({ Bucket: bucketName }).promise(); - return response.TagSet.some(tag => tag.Key === AUTO_DELETE_OBJECTS_TAG && tag.Value === 'true'); -} \ No newline at end of file