Skip to content

Commit

Permalink
Rename unzipFile flag to extract
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Makoviecki committed Sep 9, 2022
1 parent 53bce12 commit c3201c0
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 191 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-s3-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ substituting it when its deployed to the destination with the actual value.

## Keep Files Zipped

By default, files are zipped, then extracted and unzipped to the destination bucket.
You can use the option `unzipFile: false` to disable this behavior, in which case, files will remain in a zip file when deployed to S3.
By default, files are zipped, then extracted into the destination bucket.
You can use the option `extract: false` to disable this behavior, in which case, files will remain in a zip file when deployed to S3.

```ts
declare const destinationBucket: s3.Bucket;
new s3deploy.BucketDeployment(this, 'DeployMeWithoutUnzippingFilesOnDestination', {
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
destinationBucket,
unzipFile: false,
extract: false,
});
```

Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export interface BucketDeploymentProps {
readonly destinationKeyPrefix?: string;

/**
* If this is set, the zip file will be synced to the destination S3 bucket and unzipped.
* If this is set, the zip file will be synced to the destination S3 bucket and extracted.
* If false, the file will remain zipped in the destination bucket.
* @default true
*/
readonly unzipFile?: boolean;
readonly extract?: boolean;

/**
* If this is set, matching files or objects will be excluded from the deployment's sync
Expand Down Expand Up @@ -357,7 +357,7 @@ export class BucketDeployment extends Construct {
DestinationBucketName: props.destinationBucket.bucketName,
DestinationBucketKeyPrefix: props.destinationKeyPrefix,
RetainOnDelete: props.retainOnDelete,
UnzipFile: props.unzipFile,
Extract: props.extract,
Prune: props.prune ?? true,
Exclude: props.exclude,
Include: props.include,
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-s3-deployment/lib/lambda/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def cfn_error(message=None):
source_markers = props.get('SourceMarkers', None)
dest_bucket_name = props['DestinationBucketName']
dest_bucket_prefix = props.get('DestinationBucketKeyPrefix', '')
unzip_file = props.get('UnzipFile', 'true') == 'true'
extract = props.get('Extract', 'true') == 'true'
retain_on_delete = props.get('RetainOnDelete', "true") == "true"
distribution_id = props.get('DistributionId', '')
user_metadata = props.get('UserMetadata', {})
Expand Down Expand Up @@ -114,7 +114,7 @@ def cfn_error(message=None):
aws_command("s3", "rm", old_s3_dest, "--recursive")

if request_type == "Update" or request_type == "Create":
s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, unzip_file)
s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, extract)

if distribution_id:
cloudfront_invalidate(distribution_id, distribution_paths)
Expand All @@ -131,7 +131,7 @@ def cfn_error(message=None):

#---------------------------------------------------------------------------------------------------
# populate all files from s3_source_zips to a destination bucket
def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, unzip_file):
def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, extract):
# list lengths are equal
if len(s3_source_zips) != len(source_markers):
raise Exception("'source_markers' and 's3_source_zips' must be the same length")
Expand All @@ -155,7 +155,7 @@ def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, ex
s3_source_zip = s3_source_zips[i]
markers = source_markers[i]

if unzip_file:
if extract:
archive=os.path.join(workdir, str(uuid4()))
logger.info("archive: %s" % archive)
aws_command("s3", "cp", s3_source_zip, archive)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def cfn_error(message=None):
source_markers = props.get('SourceMarkers', None)
dest_bucket_name = props['DestinationBucketName']
dest_bucket_prefix = props.get('DestinationBucketKeyPrefix', '')
unzip_file = props.get('UnzipFile', 'true') == 'true'
extract = props.get('Extract', 'true') == 'true'
retain_on_delete = props.get('RetainOnDelete', "true") == "true"
distribution_id = props.get('DistributionId', '')
user_metadata = props.get('UserMetadata', {})
Expand Down Expand Up @@ -114,7 +114,7 @@ def cfn_error(message=None):
aws_command("s3", "rm", old_s3_dest, "--recursive")

if request_type == "Update" or request_type == "Create":
s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, unzip_file)
s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, extract)

if distribution_id:
cloudfront_invalidate(distribution_id, distribution_paths)
Expand All @@ -131,7 +131,7 @@ def cfn_error(message=None):

#---------------------------------------------------------------------------------------------------
# populate all files from s3_source_zips to a destination bucket
def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, unzip_file):
def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, exclude, include, source_markers, extract):
# list lengths are equal
if len(s3_source_zips) != len(source_markers):
raise Exception("'source_markers' and 's3_source_zips' must be the same length")
Expand All @@ -155,10 +155,10 @@ def s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata, prune, ex
s3_source_zip = s3_source_zips[i]
markers = source_markers[i]

archive=os.path.join(workdir, str(uuid4()))
logger.info("archive: %s" % archive)
aws_command("s3", "cp", s3_source_zip, archive)
if unzip_file:
if extract:
archive=os.path.join(workdir, str(uuid4()))
logger.info("archive: %s" % archive)
aws_command("s3", "cp", s3_source_zip, archive)
logger.info("| extracting archive to: %s\n" % contents_dir)
logger.info("| markers: %s" % markers)
extract_and_replace_markers(archive, contents_dir, markers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"stacks": [
"test-bucket-deployments-2"
],
"assertionStack": "integ-test-bucket-deployments/DefaultTest/DeployAssert"
"assertionStack": "integtestbucketdeploymentsDefaultTestDeployAssertCF25A2DF"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
{
"type": "aws:cdk:asset",
"data": {
"path": "asset.39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080.zip",
"id": "39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080",
"path": "asset.731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c.zip",
"id": "731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c",
"packaging": "file",
"sourceHash": "39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080",
"s3BucketParameter": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080S3BucketBE186C65",
"s3KeyParameter": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080S3VersionKey33D2327E",
"artifactHashParameter": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080ArtifactHashC8044924"
"sourceHash": "731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c",
"s3BucketParameter": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cS3Bucket2D8741B0",
"s3KeyParameter": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cS3VersionKeyB2BD56AC",
"artifactHashParameter": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cArtifactHashFE5C02BC"
}
},
{
"type": "aws:cdk:asset",
"data": {
"path": "asset.2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4",
"id": "2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4",
"path": "asset.bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92",
"id": "bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92",
"packaging": "zip",
"sourceHash": "2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4",
"s3BucketParameter": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4S3Bucket3A010014",
"s3KeyParameter": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4S3VersionKey69F8BD8E",
"artifactHashParameter": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4ArtifactHashF19EED8E"
"sourceHash": "bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92",
"s3BucketParameter": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92S3Bucket66717EB4",
"s3KeyParameter": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92S3VersionKey083B7E4D",
"artifactHashParameter": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92ArtifactHashA688A161"
}
},
{
Expand Down Expand Up @@ -113,40 +113,40 @@
"data": "AssetParameters60767da3831353fede3cfe92efef10580a600592dec8ccbb06c051e95b9c1b26ArtifactHashF709D3CB"
}
],
"/test-bucket-deployments-2/AssetParameters/39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080/S3Bucket": [
"/test-bucket-deployments-2/AssetParameters/731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c/S3Bucket": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080S3BucketBE186C65"
"data": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cS3Bucket2D8741B0"
}
],
"/test-bucket-deployments-2/AssetParameters/39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080/S3VersionKey": [
"/test-bucket-deployments-2/AssetParameters/731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c/S3VersionKey": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080S3VersionKey33D2327E"
"data": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cS3VersionKeyB2BD56AC"
}
],
"/test-bucket-deployments-2/AssetParameters/39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080/ArtifactHash": [
"/test-bucket-deployments-2/AssetParameters/731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873c/ArtifactHash": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters39ee629321f531fffd853b944b2d6f3fa7b5276431c9a4fd4dc681303ab15080ArtifactHashC8044924"
"data": "AssetParameters731f24951dbe4e08bfc519dd7c23a4f7158528bd5557e38437b08292ab2a873cArtifactHashFE5C02BC"
}
],
"/test-bucket-deployments-2/AssetParameters/2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4/S3Bucket": [
"/test-bucket-deployments-2/AssetParameters/bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92/S3Bucket": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4S3Bucket3A010014"
"data": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92S3Bucket66717EB4"
}
],
"/test-bucket-deployments-2/AssetParameters/2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4/S3VersionKey": [
"/test-bucket-deployments-2/AssetParameters/bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92/S3VersionKey": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4S3VersionKey69F8BD8E"
"data": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92S3VersionKey083B7E4D"
}
],
"/test-bucket-deployments-2/AssetParameters/2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4/ArtifactHash": [
"/test-bucket-deployments-2/AssetParameters/bc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92/ArtifactHash": [
{
"type": "aws:cdk:logicalId",
"data": "AssetParameters2a874a88fdd03c6bc86da13edd8da8f549948660709bd1632eb4abe1a907f1d4ArtifactHashF19EED8E"
"data": "AssetParametersbc935fa4a9499a4b71f067e37a7f05ed05bbcdbf4dc33a44747bc8da38db7e92ArtifactHashA688A161"
}
],
"/test-bucket-deployments-2/AssetParameters/fc4481abf279255619ff7418faa5d24456fef3432ea0da59c95542578ff0222e/S3Bucket": [
Expand Down Expand Up @@ -491,16 +491,16 @@
"data": "DeployMeWithExcludedFilesOnDestinationCustomResource48D69581"
}
],
"/test-bucket-deployments-2/DeployMeWithoutUnzippingFilesOnDestination/AwsCliLayer/Resource": [
"/test-bucket-deployments-2/DeployMeWithoutExtractingFilesOnDestination/AwsCliLayer/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "DeployMeWithoutUnzippingFilesOnDestinationAwsCliLayer2EF89AE5"
"data": "DeployMeWithoutExtractingFilesOnDestinationAwsCliLayerC65F79D8"
}
],
"/test-bucket-deployments-2/DeployMeWithoutUnzippingFilesOnDestination/CustomResource/Default": [
"/test-bucket-deployments-2/DeployMeWithoutExtractingFilesOnDestination/CustomResource/Default": [
{
"type": "aws:cdk:logicalId",
"data": "DeployMeWithoutUnzippingFilesOnDestinationCustomResource06B7EE3A"
"data": "DeployMeWithoutExtractingFilesOnDestinationCustomResourceF1CAAF89"
}
]
},
Expand Down
Loading

0 comments on commit c3201c0

Please sign in to comment.