diff --git a/packages/@aws-cdk/assets-docker/README.md b/packages/@aws-cdk/assets-docker/README.md index 2dc56b8ae3139..59b0515a0172f 100644 --- a/packages/@aws-cdk/assets-docker/README.md +++ b/packages/@aws-cdk/assets-docker/README.md @@ -3,62 +3,11 @@ --- -![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) +![Stability: Deprecated](https://img.shields.io/badge/stability-Deprecated-critical.svg?style=for-the-badge) -> This API is still under active development and subject to non-backward -> compatible changes or removal in any future version. Use of the API is not recommended in production -> environments. Experimental APIs are not subject to the Semantic Versioning model. +> This API may emit warnings. Backward compatibility is not guaranteed. --- -This module allows bundling Docker images as assets. - -Images are built from a local Docker context directory (with a `Dockerfile`), -uploaded to ECR by the CDK toolkit and/or your app's CI-CD pipeline, and can be -naturally referenced in your CDK app. - -```typescript -import { DockerImageAsset } from '@aws-cdk/assets-docker'; - -const asset = new DockerImageAsset(this, 'MyBuildImage', { - directory: path.join(__dirname, 'my-image') -}); -``` - -The directory `my-image` must include a `Dockerfile`. - -This will instruct the toolkit to build a Docker image from `my-image`, push it -to an AWS ECR repository and wire the name of the repository as CloudFormation -parameters to your stack. - -Use `asset.imageUri` to reference the image (it includes both the ECR image URL -and tag. - -You can optionally pass build args to the `docker build` command by specifying -the `buildArgs` property: - -```typescript -const asset = new DockerImageAsset(this, 'MyBuildImage', { - directory: path.join(__dirname, 'my-image'), - buildArgs: { - HTTP_PROXY: 'http://10.20.30.2:1234' - } -}); -``` - -### Pull Permissions - -Depending on the consumer of your image asset, you will need to make sure -the principal has permissions to pull the image. - -In most cases, you should use the `asset.repository.grantPull(principal)` -method. This will modify the IAM policy of the principal to allow it to -pull images from this repository. - -If the pulling principal is not in the same account or is an AWS service that -doesn't assume a role in your account (e.g. AWS CodeBuild), pull permissions -must be granted on the __resource policy__ (and not on the principal's policy). -To do that, you can use `asset.repository.addToResourcePolicy(statement)` to -grant the desired principal the following permissions: "ecr:GetDownloadUrlForLayer", -"ecr:BatchGetImage" and "ecr:BatchCheckLayerAvailability". +Deprecated: @aws-cdk/aws-ecr-assets \ No newline at end of file diff --git a/packages/@aws-cdk/assets-docker/lib/index.ts b/packages/@aws-cdk/assets-docker/lib/index.ts index 579fee533587d..b03033c94d008 100644 --- a/packages/@aws-cdk/assets-docker/lib/index.ts +++ b/packages/@aws-cdk/assets-docker/lib/index.ts @@ -1 +1,2 @@ -export * from './image-asset'; +// tslint:disable-next-line:no-console +console.error('the @aws-cdk/assets-docker is deprecated. use @aws-cdk/aws-ecr-assets'); diff --git a/packages/@aws-cdk/assets-docker/package.json b/packages/@aws-cdk/assets-docker/package.json index 7a2dda0109eba..118214b45b1ab 100644 --- a/packages/@aws-cdk/assets-docker/package.json +++ b/packages/@aws-cdk/assets-docker/package.json @@ -1,7 +1,8 @@ { "name": "@aws-cdk/assets-docker", "version": "0.34.0", - "description": "Docker image assets", + "deprecated": "moved to @aws-cdk/aws-ecr-assets", + "description": "deprecated: moved to @aws-cdk/aws-ecr-assets", "main": "lib/index.js", "types": "lib/index.d.ts", "jsii": { @@ -57,40 +58,13 @@ }, "license": "Apache-2.0", "devDependencies": { - "@aws-cdk/assert": "^0.34.0", - "@types/proxyquire": "^1.3.28", - "aws-cdk": "^0.34.0", "cdk-build-tools": "^0.34.0", "cdk-integ-tools": "^0.34.0", - "pkglint": "^0.34.0", - "proxyquire": "^2.1.0" - }, - "dependencies": { - "@aws-cdk/assets": "^0.34.0", - "@aws-cdk/aws-cloudformation": "^0.34.0", - "@aws-cdk/aws-ecr": "^0.34.0", - "@aws-cdk/aws-iam": "^0.34.0", - "@aws-cdk/aws-lambda": "^0.34.0", - "@aws-cdk/aws-s3": "^0.34.0", - "@aws-cdk/cdk": "^0.34.0", - "@aws-cdk/cx-api": "^0.34.0" + "pkglint": "^0.34.0" }, "homepage": "https://github.com/awslabs/aws-cdk", - "peerDependencies": { - "@aws-cdk/assets": "^0.34.0", - "@aws-cdk/aws-cloudformation": "^0.34.0", - "@aws-cdk/aws-ecr": "^0.34.0", - "@aws-cdk/aws-iam": "^0.34.0", - "@aws-cdk/aws-lambda": "^0.34.0", - "@aws-cdk/aws-s3": "^0.34.0", - "@aws-cdk/cdk": "^0.34.0", - "@aws-cdk/cx-api": "^0.34.0" - }, - "nyc": { - "statements": 70 - }, "engines": { "node": ">= 8.10.0" }, - "stability": "experimental" -} \ No newline at end of file + "stability": "deprecated" +} diff --git a/packages/@aws-cdk/assets/README.md b/packages/@aws-cdk/assets/README.md index 6c84d2da11981..bb85f84d94b1d 100644 --- a/packages/@aws-cdk/assets/README.md +++ b/packages/@aws-cdk/assets/README.md @@ -12,84 +12,5 @@ --- -Assets are local files or directories which are needed by a CDK app. A common -example is a directory which contains the handler code for a Lambda function, -but assets can represent any artifact that is needed for the app's operation. +This module includes core classes related to CDK assets. -When deploying a CDK app that includes constructs with assets, the CDK toolkit -will first upload all the assets to S3, and only then deploy the stacks. The S3 -locations of the uploaded assets will be passed in as CloudFormation Parameters -to the relevant stacks. - -The following JavaScript example defines an directory asset which is archived as -a .zip file and uploaded to S3 during deployment. - -[Example of a ZipDirectoryAsset](./test/integ.assets.directory.lit.ts) - -The following JavaScript example defines a file asset, which is uploaded as-is -to an S3 bucket during deployment. - -[Example of a FileAsset](./test/integ.assets.file.lit.ts) - -## Attributes - -`Asset` constructs expose the following deploy-time attributes: - - * `s3BucketName` - the name of the assets S3 bucket. - * `s3ObjectKey` - the S3 object key of the asset file (whether it's a file or a zip archive) - * `s3Url` - the S3 URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) - -In the following example, the various asset attributes are exported as stack outputs: - -[Example of referencing an asset](./test/integ.assets.refs.lit.ts) - -## Permissions - -IAM roles, users or groups which need to be able to read assets in runtime will should be -granted IAM permissions. To do that use the `asset.grantRead(principal)` method: - -The following examples grants an IAM group read permissions on an asset: - -[Example of granting read access to an asset](./test/integ.assets.permissions.lit.ts) - -## How does it work? - -When an asset is defined in a construct, a construct metadata entry -`aws:cdk:asset` is emitted with instructions on where to find the asset and what -type of packaging to perform (`zip` or `file`). Furthermore, the synthesized -CloudFormation template will also include two CloudFormation parameters: one for -the asset's bucket and one for the asset S3 key. Those parameters are used to -reference the deploy-time values of the asset (using `{ Ref: "Param" }`). - -Then, when the stack is deployed, the toolkit will package the asset (i.e. zip -the directory), calculate an MD5 hash of the contents and will render an S3 key -for this asset within the toolkit's asset store. If the file doesn't exist in -the asset store, it is uploaded during deployment. - -> The toolkit's asset store is an S3 bucket created by the toolkit for each - environment the toolkit operates in (environment = account + region). - -Now, when the toolkit deploys the stack, it will set the relevant CloudFormation -Parameters to point to the actual bucket and key for each asset. - -## CloudFormation Resource Metadata - -> NOTE: This section is relevant for authors of AWS Resource Constructs. - -In certain situations, it is desirable for tools to be able to know that a certain CloudFormation -resource is using a local asset. For example, SAM CLI can be used to invoke AWS Lambda functions -locally for debugging purposes. - -To enable such use cases, external tools will consult a set of metadata entries on AWS CloudFormation -resources: - -- `aws:asset:path` points to the local path of the asset. -- `aws:asset:property` is the name of the resource property where the asset is used - -Using these two metadata entries, tools will be able to identify that assets are used -by a certain resource, and enable advanced local experiences. - -To add these metadata entries to a resource, use the -`asset.addResourceMetadata(resource, property)` method. - -See https://github.com/awslabs/aws-cdk/issues/1432 for more details diff --git a/packages/@aws-cdk/assets/lib/api.ts b/packages/@aws-cdk/assets/lib/api.ts new file mode 100644 index 0000000000000..c06f3295ad5ba --- /dev/null +++ b/packages/@aws-cdk/assets/lib/api.ts @@ -0,0 +1,20 @@ +/** + * Common interface for all assets. + */ +export interface IAsset { + /** + * A hash of the source of this asset, which is available at construction time. As this is a plain + * string, it can be used in construct IDs in order to enforce creation of a new resource when + * the content hash has changed. + */ + readonly sourceHash: string; + + /** + * A hash of the bundle for of this asset, which is only available at deployment time. As this is + * a late-bound token, it may not be used in construct IDs, but can be passed as a resource + * property in order to force a change on a resource when an asset is effectively updated. This is + * more reliable than `sourceHash` in particular for assets which bundling phase involve external + * resources that can change over time (such as Docker image builds). + */ + readonly artifactHash: string; +} diff --git a/packages/@aws-cdk/assets/lib/index.ts b/packages/@aws-cdk/assets/lib/index.ts index e57823463b2aa..fffa67ab1b17f 100644 --- a/packages/@aws-cdk/assets/lib/index.ts +++ b/packages/@aws-cdk/assets/lib/index.ts @@ -1,4 +1,4 @@ -export * from './asset'; export * from './fs/copy-options'; export * from './fs/follow-mode'; export * from './staging'; +export * from './api'; diff --git a/packages/@aws-cdk/assets/lib/staging.ts b/packages/@aws-cdk/assets/lib/staging.ts index 59340eac4edbd..1ab9a32b3d017 100644 --- a/packages/@aws-cdk/assets/lib/staging.ts +++ b/packages/@aws-cdk/assets/lib/staging.ts @@ -12,7 +12,7 @@ export interface StagingProps extends CopyOptions { * Stages a file or directory from a location on the file system into a staging * directory. * - * This is controlled by the context key 'aws:cdk:asset-staging-dir' and enabled + * This is controlled by the context key 'aws:cdk:asset-staging' and enabled * by the CLI by default in order to ensure that when the CDK app exists, all * assets are available for deployment. Otherwise, if an app references assets * in temporary locations, those will not be available when it exists (see diff --git a/packages/@aws-cdk/assets/package.json b/packages/@aws-cdk/assets/package.json index 0ff28204223ca..b411305c713e4 100644 --- a/packages/@aws-cdk/assets/package.json +++ b/packages/@aws-cdk/assets/package.json @@ -72,16 +72,12 @@ "ts-mock-imports": "^1.2.3" }, "dependencies": { - "@aws-cdk/aws-iam": "^0.34.0", - "@aws-cdk/aws-s3": "^0.34.0", "@aws-cdk/cdk": "^0.34.0", "@aws-cdk/cx-api": "^0.34.0", "minimatch": "^3.0.4" }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { - "@aws-cdk/aws-iam": "^0.34.0", - "@aws-cdk/aws-s3": "^0.34.0", "@aws-cdk/cdk": "^0.34.0", "@aws-cdk/cx-api": "^0.34.0" }, diff --git a/packages/@aws-cdk/assets/test/test.staging.ts b/packages/@aws-cdk/assets/test/test.staging.ts new file mode 100644 index 0000000000000..5b316e3b1a0cc --- /dev/null +++ b/packages/@aws-cdk/assets/test/test.staging.ts @@ -0,0 +1,60 @@ +import { App, Stack } from '@aws-cdk/cdk'; +import cxapi = require('@aws-cdk/cx-api'); +import fs = require('fs'); +import { Test } from 'nodeunit'; +import path = require('path'); +import { Staging } from '../lib'; + +export = { + 'base case'(test: Test) { + // GIVEN + const stack = new Stack(); + const sourcePath = path.join(__dirname, 'fs', 'fixtures', 'test1'); + + // WHEN + const staging = new Staging(stack, 's1', { sourcePath }); + + test.deepEqual(staging.sourceHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00'); + test.deepEqual(staging.sourcePath, sourcePath); + test.deepEqual(stack.resolve(staging.stagedPath), 'asset.2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00'); + test.done(); + }, + + 'staging can be disabled through context'(test: Test) { + // GIVEN + const stack = new Stack(); + stack.node.setContext(cxapi.DISABLE_ASSET_STAGING_CONTEXT, true); + const sourcePath = path.join(__dirname, 'fs', 'fixtures', 'test1'); + + // WHEN + const staging = new Staging(stack, 's1', { sourcePath }); + + test.deepEqual(staging.sourceHash, '2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00'); + test.deepEqual(staging.sourcePath, sourcePath); + test.deepEqual(stack.resolve(staging.stagedPath), sourcePath); + test.done(); + }, + + 'files are copied to the output directory during synth'(test: Test) { + // GIVEN + const app = new App(); + const stack = new Stack(app, 'stack'); + const directory = path.join(__dirname, 'fs', 'fixtures', 'test1'); + const file = path.join(__dirname, 'fs', 'fixtures.tar.gz'); + + // WHEN + new Staging(stack, 's1', { sourcePath: directory }); + new Staging(stack, 'file', { sourcePath: file }); + + // THEN + const assembly = app.synth(); + test.deepEqual(fs.readdirSync(assembly.directory), [ + 'asset.2f37f937c51e2c191af66acf9b09f548926008ec68c575bd2ee54b6e997c0e00', + 'asset.af10ac04b3b607b0f8659c8f0cee8c343025ee75baf0b146f10f0e5311d2c46b.gz', + 'cdk.out', + 'manifest.json', + 'stack.template.json' + ]); + test.done(); + } +}; \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index 053ed6c824fed..f332818b631d7 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -1,7 +1,7 @@ -import { DockerImageAsset, DockerImageAssetProps } from '@aws-cdk/assets-docker'; import cloudwatch = require('@aws-cdk/aws-cloudwatch'); import ec2 = require('@aws-cdk/aws-ec2'); import ecr = require('@aws-cdk/aws-ecr'); +import { DockerImageAsset, DockerImageAssetProps } from '@aws-cdk/aws-ecr-assets'; import events = require('@aws-cdk/aws-events'); import iam = require('@aws-cdk/aws-iam'); import kms = require('@aws-cdk/aws-kms'); diff --git a/packages/@aws-cdk/aws-codebuild/package.json b/packages/@aws-cdk/aws-codebuild/package.json index c18b6e2a9eb64..d44b112ac38a7 100644 --- a/packages/@aws-cdk/aws-codebuild/package.json +++ b/packages/@aws-cdk/aws-codebuild/package.json @@ -77,8 +77,9 @@ "pkglint": "^0.34.0" }, "dependencies": { + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/assets": "^0.34.0", - "@aws-cdk/assets-docker": "^0.34.0", + "@aws-cdk/aws-ecr-assets": "^0.34.0", "@aws-cdk/aws-cloudwatch": "^0.34.0", "@aws-cdk/aws-codecommit": "^0.34.0", "@aws-cdk/aws-ec2": "^0.34.0", @@ -91,8 +92,9 @@ }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/assets": "^0.34.0", - "@aws-cdk/assets-docker": "^0.34.0", + "@aws-cdk/aws-ecr-assets": "^0.34.0", "@aws-cdk/aws-cloudwatch": "^0.34.0", "@aws-cdk/aws-codecommit": "^0.34.0", "@aws-cdk/aws-ec2": "^0.34.0", @@ -112,4 +114,4 @@ ] }, "stability": "experimental" -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-ecr-assets/.gitignore b/packages/@aws-cdk/aws-ecr-assets/.gitignore new file mode 100644 index 0000000000000..2a7ab813ef1bf --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/.gitignore @@ -0,0 +1,17 @@ +*.js +*.js.map +*.d.ts +node_modules +dist +tsconfig.json +tslint.json + +.LAST_BUILD +.nyc_output +coverage + +.jsii + +.nycrc +.LAST_PACKAGE +*.snk \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecr-assets/.npmignore b/packages/@aws-cdk/aws-ecr-assets/.npmignore new file mode 100644 index 0000000000000..f5a63a96df103 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/.npmignore @@ -0,0 +1,18 @@ +# Don't include original .ts files when doing `npm pack` +*.ts +!*.d.ts +coverage +.nyc_output +*.tgz + +dist +.LAST_PACKAGE +.LAST_BUILD +!*.js + +# Include .jsii +!.jsii + +*.snk + +*.tsbuildinfo diff --git a/packages/@aws-cdk/aws-ecr-assets/LICENSE b/packages/@aws-cdk/aws-ecr-assets/LICENSE new file mode 100644 index 0000000000000..46c185646b439 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/@aws-cdk/aws-ecr-assets/NOTICE b/packages/@aws-cdk/aws-ecr-assets/NOTICE new file mode 100644 index 0000000000000..8585168af8b7d --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/NOTICE @@ -0,0 +1,2 @@ +AWS Cloud Development Kit (AWS CDK) +Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/aws-ecr-assets/README.md b/packages/@aws-cdk/aws-ecr-assets/README.md new file mode 100644 index 0000000000000..2dc56b8ae3139 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/README.md @@ -0,0 +1,64 @@ +# AWS CDK Docker Image Assets + + +--- + +![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) + +> This API is still under active development and subject to non-backward +> compatible changes or removal in any future version. Use of the API is not recommended in production +> environments. Experimental APIs are not subject to the Semantic Versioning model. + +--- + + +This module allows bundling Docker images as assets. + +Images are built from a local Docker context directory (with a `Dockerfile`), +uploaded to ECR by the CDK toolkit and/or your app's CI-CD pipeline, and can be +naturally referenced in your CDK app. + +```typescript +import { DockerImageAsset } from '@aws-cdk/assets-docker'; + +const asset = new DockerImageAsset(this, 'MyBuildImage', { + directory: path.join(__dirname, 'my-image') +}); +``` + +The directory `my-image` must include a `Dockerfile`. + +This will instruct the toolkit to build a Docker image from `my-image`, push it +to an AWS ECR repository and wire the name of the repository as CloudFormation +parameters to your stack. + +Use `asset.imageUri` to reference the image (it includes both the ECR image URL +and tag. + +You can optionally pass build args to the `docker build` command by specifying +the `buildArgs` property: + +```typescript +const asset = new DockerImageAsset(this, 'MyBuildImage', { + directory: path.join(__dirname, 'my-image'), + buildArgs: { + HTTP_PROXY: 'http://10.20.30.2:1234' + } +}); +``` + +### Pull Permissions + +Depending on the consumer of your image asset, you will need to make sure +the principal has permissions to pull the image. + +In most cases, you should use the `asset.repository.grantPull(principal)` +method. This will modify the IAM policy of the principal to allow it to +pull images from this repository. + +If the pulling principal is not in the same account or is an AWS service that +doesn't assume a role in your account (e.g. AWS CodeBuild), pull permissions +must be granted on the __resource policy__ (and not on the principal's policy). +To do that, you can use `asset.repository.addToResourcePolicy(statement)` to +grant the desired principal the following permissions: "ecr:GetDownloadUrlForLayer", +"ecr:BatchGetImage" and "ecr:BatchCheckLayerAvailability". diff --git a/packages/@aws-cdk/assets-docker/lib/adopt-repository/.gitignore b/packages/@aws-cdk/aws-ecr-assets/lib/adopt-repository/.gitignore similarity index 100% rename from packages/@aws-cdk/assets-docker/lib/adopt-repository/.gitignore rename to packages/@aws-cdk/aws-ecr-assets/lib/adopt-repository/.gitignore diff --git a/packages/@aws-cdk/assets-docker/lib/adopt-repository/handler.js b/packages/@aws-cdk/aws-ecr-assets/lib/adopt-repository/handler.js similarity index 100% rename from packages/@aws-cdk/assets-docker/lib/adopt-repository/handler.js rename to packages/@aws-cdk/aws-ecr-assets/lib/adopt-repository/handler.js diff --git a/packages/@aws-cdk/assets-docker/lib/adopted-repository.ts b/packages/@aws-cdk/aws-ecr-assets/lib/adopted-repository.ts similarity index 100% rename from packages/@aws-cdk/assets-docker/lib/adopted-repository.ts rename to packages/@aws-cdk/aws-ecr-assets/lib/adopted-repository.ts diff --git a/packages/@aws-cdk/assets-docker/lib/image-asset.ts b/packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts similarity index 100% rename from packages/@aws-cdk/assets-docker/lib/image-asset.ts rename to packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts diff --git a/packages/@aws-cdk/aws-ecr-assets/lib/index.ts b/packages/@aws-cdk/aws-ecr-assets/lib/index.ts new file mode 100644 index 0000000000000..579fee533587d --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/lib/index.ts @@ -0,0 +1 @@ +export * from './image-asset'; diff --git a/packages/@aws-cdk/aws-ecr-assets/package-lock.json b/packages/@aws-cdk/aws-ecr-assets/package-lock.json new file mode 100644 index 0000000000000..6aff698c6ea31 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/package-lock.json @@ -0,0 +1,68 @@ +{ + "name": "@aws-cdk/assets-docker", + "version": "0.34.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/proxyquire": { + "version": "1.3.28", + "resolved": "https://registry.npmjs.org/@types/proxyquire/-/proxyquire-1.3.28.tgz", + "integrity": "sha512-SQaNzWQ2YZSr7FqAyPPiA3FYpux2Lqh3HWMZQk47x3xbMCqgC/w0dY3dw9rGqlweDDkrySQBcaScXWeR+Yb11Q==", + "dev": true + }, + "fill-keys": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz", + "integrity": "sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA=", + "dev": true, + "requires": { + "is-object": "~1.0.1", + "merge-descriptors": "~1.0.0" + } + }, + "is-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz", + "integrity": "sha1-iVJojF7C/9awPsyF52ngKQMINHA=", + "dev": true + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", + "dev": true + }, + "module-not-found-error": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz", + "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "proxyquire": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-2.1.0.tgz", + "integrity": "sha512-kptdFArCfGRtQFv3Qwjr10lwbEV0TBJYvfqzhwucyfEXqVgmnAkyEw/S3FYzR5HI9i5QOq4rcqQjZ6AlknlCDQ==", + "dev": true, + "requires": { + "fill-keys": "^1.0.2", + "module-not-found-error": "^1.0.0", + "resolve": "~1.8.1" + } + }, + "resolve": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", + "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", + "dev": true, + "requires": { + "path-parse": "^1.0.5" + } + } + } +} diff --git a/packages/@aws-cdk/aws-ecr-assets/package.json b/packages/@aws-cdk/aws-ecr-assets/package.json new file mode 100644 index 0000000000000..b29d964a1fdb3 --- /dev/null +++ b/packages/@aws-cdk/aws-ecr-assets/package.json @@ -0,0 +1,96 @@ +{ + "name": "@aws-cdk/aws-ecr-assets", + "version": "0.34.0", + "description": "Docker image assets deployed to ECR", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awscdk.services.ecr.assets", + "maven": { + "groupId": "software.amazon.awscdk", + "artifactId": "ecr-assets" + } + }, + "dotnet": { + "namespace": "Amazon.CDK.AWS.Ecr.Assets", + "packageId": "Amazon.CDK.ECR.Assets", + "signAssembly": true, + "assemblyOriginatorKeyFile": "../../key.snk" + }, + "python": { + "distName": "aws-cdk.aws-ecr-assets", + "module": "aws_cdk.aws_ecr_assets" + } + } + }, + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-cdk.git", + "directory": "packages/@aws-cdk/aws-ecr-assets" + }, + "scripts": { + "build": "cdk-build", + "watch": "cdk-watch", + "lint": "cdk-lint", + "test": "cdk-test", + "integ": "cdk-integ", + "pkglint": "pkglint -f", + "package": "cdk-package", + "awslint": "cdk-awslint", + "build+test+package": "npm run build+test && npm run package", + "build+test": "npm run build && npm test" + }, + "keywords": [ + "aws", + "cdk", + "constructs", + "assets", + "docker" + ], + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "devDependencies": { + "@aws-cdk/assert": "^0.34.0", + "@types/proxyquire": "^1.3.28", + "aws-cdk": "^0.34.0", + "cdk-build-tools": "^0.34.0", + "cdk-integ-tools": "^0.34.0", + "pkglint": "^0.34.0", + "proxyquire": "^2.1.0" + }, + "dependencies": { + "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-cloudformation": "^0.34.0", + "@aws-cdk/aws-ecr": "^0.34.0", + "@aws-cdk/aws-iam": "^0.34.0", + "@aws-cdk/aws-lambda": "^0.34.0", + "@aws-cdk/aws-s3": "^0.34.0", + "@aws-cdk/cdk": "^0.34.0", + "@aws-cdk/cx-api": "^0.34.0" + }, + "homepage": "https://github.com/awslabs/aws-cdk", + "peerDependencies": { + "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-cloudformation": "^0.34.0", + "@aws-cdk/aws-ecr": "^0.34.0", + "@aws-cdk/aws-iam": "^0.34.0", + "@aws-cdk/aws-lambda": "^0.34.0", + "@aws-cdk/aws-s3": "^0.34.0", + "@aws-cdk/cdk": "^0.34.0", + "@aws-cdk/cx-api": "^0.34.0" + }, + "nyc": { + "statements": 70 + }, + "engines": { + "node": ">= 8.10.0" + }, + "stability": "experimental" +} diff --git a/packages/@aws-cdk/assets-docker/test/demo-image/Dockerfile b/packages/@aws-cdk/aws-ecr-assets/test/demo-image/Dockerfile similarity index 100% rename from packages/@aws-cdk/assets-docker/test/demo-image/Dockerfile rename to packages/@aws-cdk/aws-ecr-assets/test/demo-image/Dockerfile diff --git a/packages/@aws-cdk/assets-docker/test/demo-image/index.py b/packages/@aws-cdk/aws-ecr-assets/test/demo-image/index.py similarity index 100% rename from packages/@aws-cdk/assets-docker/test/demo-image/index.py rename to packages/@aws-cdk/aws-ecr-assets/test/demo-image/index.py diff --git a/packages/@aws-cdk/assets-docker/test/integ.assets-docker.expected.json b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.expected.json similarity index 100% rename from packages/@aws-cdk/assets-docker/test/integ.assets-docker.expected.json rename to packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.expected.json diff --git a/packages/@aws-cdk/assets-docker/test/integ.assets-docker.ts b/packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts similarity index 100% rename from packages/@aws-cdk/assets-docker/test/integ.assets-docker.ts rename to packages/@aws-cdk/aws-ecr-assets/test/integ.assets-docker.ts diff --git a/packages/@aws-cdk/assets-docker/test/test.adpot-repo.ts b/packages/@aws-cdk/aws-ecr-assets/test/test.adpot-repo.ts similarity index 100% rename from packages/@aws-cdk/assets-docker/test/test.adpot-repo.ts rename to packages/@aws-cdk/aws-ecr-assets/test/test.adpot-repo.ts diff --git a/packages/@aws-cdk/assets-docker/test/test.image-asset.ts b/packages/@aws-cdk/aws-ecr-assets/test/test.image-asset.ts similarity index 100% rename from packages/@aws-cdk/assets-docker/test/test.image-asset.ts rename to packages/@aws-cdk/aws-ecr-assets/test/test.image-asset.ts diff --git a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts index 231ae5eb0f179..2030ee8c6fe16 100644 --- a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts +++ b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts @@ -1,4 +1,4 @@ -import { DockerImageAsset } from '@aws-cdk/assets-docker'; +import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets'; import cdk = require('@aws-cdk/cdk'); import { ContainerDefinition } from '../container-definition'; import { ContainerImage, ContainerImageConfig } from '../container-image'; diff --git a/packages/@aws-cdk/aws-ecs/package.json b/packages/@aws-cdk/aws-ecs/package.json index 46f5919359936..7daeea38840e0 100644 --- a/packages/@aws-cdk/aws-ecs/package.json +++ b/packages/@aws-cdk/aws-ecs/package.json @@ -72,7 +72,7 @@ "proxyquire": "^2.1.0" }, "dependencies": { - "@aws-cdk/assets-docker": "^0.34.0", + "@aws-cdk/aws-ecr-assets": "^0.34.0", "@aws-cdk/aws-applicationautoscaling": "^0.34.0", "@aws-cdk/aws-autoscaling": "^0.34.0", "@aws-cdk/aws-autoscaling-hooktargets": "^0.34.0", @@ -97,7 +97,7 @@ }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { - "@aws-cdk/assets-docker": "^0.34.0", + "@aws-cdk/aws-ecr-assets": "^0.34.0", "@aws-cdk/aws-applicationautoscaling": "^0.34.0", "@aws-cdk/aws-autoscaling": "^0.34.0", "@aws-cdk/aws-autoscaling-hooktargets": "^0.34.0", @@ -124,4 +124,4 @@ "node": ">= 8.10.0" }, "stability": "experimental" -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index 5f097cddbdffa..350656ec1c892 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -1,7 +1,6 @@ -import assets = require('@aws-cdk/assets'); import s3 = require('@aws-cdk/aws-s3'); +import s3_assets = require('@aws-cdk/aws-s3-assets'); import cdk = require('@aws-cdk/cdk'); -import fs = require('fs'); import { CfnFunction } from './lambda.generated'; export abstract class Code { @@ -31,25 +30,6 @@ export abstract class Code { return new AssetCode(path); } - /** - * @returns Zip archives the contents of a directory on disk and uses this - * as the lambda handler's code. - * @param directoryToZip The directory to zip - * @deprecated use `lambda.Code.asset(path)` (no need to specify if it's a file or a directory) - */ - public static directory(directoryToZip: string): AssetCode { - return new AssetCode(directoryToZip, assets.AssetPackaging.ZipDirectory); - } - - /** - * @returns Uses a file on disk as a lambda handler's code. - * @param filePath The file path - * @deprecated use `lambda.Code.asset(path)` (no need to specify if it's a file or a directory) - */ - public static file(filePath: string): AssetCode { - return new AssetCode(filePath, assets.AssetPackaging.File); - } - /** * Creates a new Lambda source defined using CloudFormation parameters. * @@ -149,37 +129,19 @@ export class InlineCode extends Code { */ export class AssetCode extends Code { public readonly isInline = false; - - /** - * The asset packaging. - */ - public readonly packaging: assets.AssetPackaging; - - private asset?: assets.Asset; + private asset?: s3_assets.Asset; /** * @param path The path to the asset file or directory. - * @param packaging The asset packaging format (optional, determined automatically) */ - constructor(public readonly path: string, packaging?: assets.AssetPackaging) { + constructor(public readonly path: string) { super(); - - if (packaging !== undefined) { - this.packaging = packaging; - } else { - this.packaging = fs.lstatSync(path).isDirectory() - ? assets.AssetPackaging.ZipDirectory - : assets.AssetPackaging.File; - } } public bind(construct: cdk.Construct) { // If the same AssetCode is used multiple times, retain only the first instantiation. if (!this.asset) { - this.asset = new assets.Asset(construct, 'Code', { - path: this.path, - packaging: this.packaging - }); + this.asset = new s3_assets.Asset(construct, 'Code', { path: this.path }); } if (!this.asset.isZipArchive) { diff --git a/packages/@aws-cdk/aws-lambda/package.json b/packages/@aws-cdk/aws-lambda/package.json index 3f055fa4bbaa6..31580ec9a37d0 100644 --- a/packages/@aws-cdk/aws-lambda/package.json +++ b/packages/@aws-cdk/aws-lambda/package.json @@ -83,7 +83,7 @@ "sinon": "^7.3.2" }, "dependencies": { - "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/aws-cloudwatch": "^0.34.0", "@aws-cdk/aws-ec2": "^0.34.0", "@aws-cdk/aws-events": "^0.34.0", @@ -96,7 +96,7 @@ }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { - "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/aws-cloudwatch": "^0.34.0", "@aws-cdk/aws-ec2": "^0.34.0", "@aws-cdk/aws-events": "^0.34.0", diff --git a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts index 1d2ea17399f18..b3aa328d27567 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts @@ -8,7 +8,7 @@ class TestStack extends cdk.Stack { /// !show new lambda.Function(this, 'MyLambda', { - code: lambda.Code.file(path.join(__dirname, 'handler.zip')), + code: lambda.Code.asset(path.join(__dirname, 'handler.zip')), handler: 'index.main', runtime: lambda.Runtime.Python36 }); diff --git a/packages/@aws-cdk/aws-lambda/test/integ.layer-version.lit.ts b/packages/@aws-cdk/aws-lambda/test/integ.layer-version.lit.ts index b86197b8991d3..89ec3b6a1bf22 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.layer-version.lit.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.layer-version.lit.ts @@ -11,7 +11,7 @@ const awsAccountId = stack.account; /// !show const layer = new lambda.LayerVersion(stack, 'MyLayer', { - code: lambda.Code.directory(path.join(__dirname, 'layer-code')), + code: lambda.Code.asset(path.join(__dirname, 'layer-code')), compatibleRuntimes: [lambda.Runtime.Nodejs810], license: 'Apache-2.0', description: 'A layer to test the L2 construct', diff --git a/packages/@aws-cdk/aws-lambda/test/test.code.ts b/packages/@aws-cdk/aws-lambda/test/test.code.ts index d60ebd6c1abf2..d262c9b56715b 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.code.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.code.ts @@ -1,5 +1,4 @@ import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert'; -import assets = require('@aws-cdk/assets'); import cdk = require('@aws-cdk/cdk'); import cxapi = require('@aws-cdk/cx-api'); import { Test } from 'nodeunit'; @@ -23,17 +22,6 @@ export = { } }, 'lambda.Code.asset': { - 'determines packaging type from file type'(test: Test) { - // WHEN - const fileAsset = lambda.Code.asset(path.join(__dirname, 'handler.zip')); - const directoryAsset = lambda.Code.asset(path.join(__dirname, 'my-lambda-handler')); - - // THEN - test.deepEqual(fileAsset.packaging, assets.AssetPackaging.File); - test.deepEqual(directoryAsset.packaging, assets.AssetPackaging.ZipDirectory); - test.done(); - }, - 'fails if a non-zip asset is used'(test: Test) { // GIVEN const fileAsset = lambda.Code.asset(path.join(__dirname, 'my-lambda-handler', 'index.py')); diff --git a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts index f12c2ad7275a3..bc29497c4f59c 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts @@ -258,7 +258,7 @@ export = { // GIVEN const stack = new cdk.Stack(); new lambda.Function(stack, 'MyLambda', { - code: lambda.Code.directory(path.join(__dirname, 'my-lambda-handler')), + code: lambda.Code.asset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', runtime: lambda.Runtime.Python36 }); diff --git a/packages/@aws-cdk/aws-s3-assets/.gitignore b/packages/@aws-cdk/aws-s3-assets/.gitignore new file mode 100644 index 0000000000000..2a7ab813ef1bf --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/.gitignore @@ -0,0 +1,17 @@ +*.js +*.js.map +*.d.ts +node_modules +dist +tsconfig.json +tslint.json + +.LAST_BUILD +.nyc_output +coverage + +.jsii + +.nycrc +.LAST_PACKAGE +*.snk \ No newline at end of file diff --git a/packages/@aws-cdk/aws-s3-assets/.npmignore b/packages/@aws-cdk/aws-s3-assets/.npmignore new file mode 100644 index 0000000000000..f5a63a96df103 --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/.npmignore @@ -0,0 +1,18 @@ +# Don't include original .ts files when doing `npm pack` +*.ts +!*.d.ts +coverage +.nyc_output +*.tgz + +dist +.LAST_PACKAGE +.LAST_BUILD +!*.js + +# Include .jsii +!.jsii + +*.snk + +*.tsbuildinfo diff --git a/packages/@aws-cdk/aws-s3-assets/LICENSE b/packages/@aws-cdk/aws-s3-assets/LICENSE new file mode 100644 index 0000000000000..46c185646b439 --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/@aws-cdk/aws-s3-assets/NOTICE b/packages/@aws-cdk/aws-s3-assets/NOTICE new file mode 100644 index 0000000000000..8585168af8b7d --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/NOTICE @@ -0,0 +1,2 @@ +AWS Cloud Development Kit (AWS CDK) +Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md new file mode 100644 index 0000000000000..6c84d2da11981 --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -0,0 +1,95 @@ +## AWS CDK Assets + + +--- + +![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) + +> This API is still under active development and subject to non-backward +> compatible changes or removal in any future version. Use of the API is not recommended in production +> environments. Experimental APIs are not subject to the Semantic Versioning model. + +--- + + +Assets are local files or directories which are needed by a CDK app. A common +example is a directory which contains the handler code for a Lambda function, +but assets can represent any artifact that is needed for the app's operation. + +When deploying a CDK app that includes constructs with assets, the CDK toolkit +will first upload all the assets to S3, and only then deploy the stacks. The S3 +locations of the uploaded assets will be passed in as CloudFormation Parameters +to the relevant stacks. + +The following JavaScript example defines an directory asset which is archived as +a .zip file and uploaded to S3 during deployment. + +[Example of a ZipDirectoryAsset](./test/integ.assets.directory.lit.ts) + +The following JavaScript example defines a file asset, which is uploaded as-is +to an S3 bucket during deployment. + +[Example of a FileAsset](./test/integ.assets.file.lit.ts) + +## Attributes + +`Asset` constructs expose the following deploy-time attributes: + + * `s3BucketName` - the name of the assets S3 bucket. + * `s3ObjectKey` - the S3 object key of the asset file (whether it's a file or a zip archive) + * `s3Url` - the S3 URL of the asset (i.e. https://s3.us-east-1.amazonaws.com/mybucket/mykey.zip) + +In the following example, the various asset attributes are exported as stack outputs: + +[Example of referencing an asset](./test/integ.assets.refs.lit.ts) + +## Permissions + +IAM roles, users or groups which need to be able to read assets in runtime will should be +granted IAM permissions. To do that use the `asset.grantRead(principal)` method: + +The following examples grants an IAM group read permissions on an asset: + +[Example of granting read access to an asset](./test/integ.assets.permissions.lit.ts) + +## How does it work? + +When an asset is defined in a construct, a construct metadata entry +`aws:cdk:asset` is emitted with instructions on where to find the asset and what +type of packaging to perform (`zip` or `file`). Furthermore, the synthesized +CloudFormation template will also include two CloudFormation parameters: one for +the asset's bucket and one for the asset S3 key. Those parameters are used to +reference the deploy-time values of the asset (using `{ Ref: "Param" }`). + +Then, when the stack is deployed, the toolkit will package the asset (i.e. zip +the directory), calculate an MD5 hash of the contents and will render an S3 key +for this asset within the toolkit's asset store. If the file doesn't exist in +the asset store, it is uploaded during deployment. + +> The toolkit's asset store is an S3 bucket created by the toolkit for each + environment the toolkit operates in (environment = account + region). + +Now, when the toolkit deploys the stack, it will set the relevant CloudFormation +Parameters to point to the actual bucket and key for each asset. + +## CloudFormation Resource Metadata + +> NOTE: This section is relevant for authors of AWS Resource Constructs. + +In certain situations, it is desirable for tools to be able to know that a certain CloudFormation +resource is using a local asset. For example, SAM CLI can be used to invoke AWS Lambda functions +locally for debugging purposes. + +To enable such use cases, external tools will consult a set of metadata entries on AWS CloudFormation +resources: + +- `aws:asset:path` points to the local path of the asset. +- `aws:asset:property` is the name of the resource property where the asset is used + +Using these two metadata entries, tools will be able to identify that assets are used +by a certain resource, and enable advanced local experiences. + +To add these metadata entries to a resource, use the +`asset.addResourceMetadata(resource, property)` method. + +See https://github.com/awslabs/aws-cdk/issues/1432 for more details diff --git a/packages/@aws-cdk/assets/lib/asset.ts b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts similarity index 66% rename from packages/@aws-cdk/assets/lib/asset.ts rename to packages/@aws-cdk/aws-s3-assets/lib/asset.ts index 8824fb0dfdf96..d2f6d45ff5e5f 100644 --- a/packages/@aws-cdk/assets/lib/asset.ts +++ b/packages/@aws-cdk/aws-s3-assets/lib/asset.ts @@ -1,11 +1,12 @@ +import assets = require('@aws-cdk/assets'); import iam = require('@aws-cdk/aws-iam'); import s3 = require('@aws-cdk/aws-s3'); import cdk = require('@aws-cdk/cdk'); import cxapi = require('@aws-cdk/cx-api'); import fs = require('fs'); import path = require('path'); -import { CopyOptions } from './fs/copy-options'; -import { Staging } from './staging'; + +const ARCHIVE_EXTENSIONS = [ '.zip', '.jar' ]; /** * Defines the way an asset is packaged before it is uploaded to S3. @@ -23,17 +24,16 @@ export enum AssetPackaging { File = 'file', } -export interface AssetProps extends CopyOptions { +export interface AssetProps extends assets.CopyOptions { /** * The disk location of the asset. + * + * The path should refer to one of the following: + * - A regular file or a .zip file, in which case the file will be uploaded as-is to S3. + * - A directory, in which case it will be archived into a .zip file and uploaded to S3. */ readonly path: string; - /** - * The packaging type for this asset. - */ - readonly packaging: AssetPackaging; - /** * A list of principals that should be able to read this asset from S3. * You can use `asset.grantRead(principal)` to grant read permissions later. @@ -43,29 +43,11 @@ export interface AssetProps extends CopyOptions { readonly readers?: iam.IGrantable[]; } -export interface IAsset extends cdk.IConstruct { - /** - * A hash of the source of this asset, which is available at construction time. As this is a plain - * string, it can be used in construct IDs in order to enforce creation of a new resource when - * the content hash has changed. - */ - readonly sourceHash: string; - - /** - * A hash of the bundle for of this asset, which is only available at deployment time. As this is - * a late-bound token, it may not be used in construct IDs, but can be passed as a resource - * property in order to force a change on a resource when an asset is effectively updated. This is - * more reliable than `sourceHash` in particular for assets which bundling phase involve external - * resources that can change over time (such as Docker image builds). - */ - readonly artifactHash: string; -} - /** * An asset represents a local file or directory, which is automatically uploaded to S3 * and then can be referenced within a CDK application. */ -export class Asset extends cdk.Construct implements IAsset { +export class Asset extends cdk.Construct implements assets.IAsset { /** * Attribute that represents the name of the bucket this asset exists in. */ @@ -113,7 +95,7 @@ export class Asset extends cdk.Construct implements IAsset { super(scope, id); // stage the asset source (conditionally). - const staging = new Staging(this, 'Stage', { + const staging = new assets.Staging(this, 'Stage', { ...props, sourcePath: path.resolve(props.path), }); @@ -121,13 +103,12 @@ export class Asset extends cdk.Construct implements IAsset { this.assetPath = staging.stagedPath; + const packaging = determinePackaging(staging.sourcePath); + // sets isZipArchive based on the type of packaging and file extension - const allowedExtensions: string[] = ['.jar', '.zip']; - this.isZipArchive = props.packaging === AssetPackaging.ZipDirectory + this.isZipArchive = packaging === AssetPackaging.ZipDirectory ? true - : allowedExtensions.some(ext => staging.sourcePath.toLowerCase().endsWith(ext)); - - validateAssetOnDisk(staging.sourcePath, props.packaging); + : ARCHIVE_EXTENSIONS.some(ext => staging.sourcePath.toLowerCase().endsWith(ext)); // add parameters for s3 bucket and s3 key. those will be set by // the toolkit or by CI/CD when the stack is deployed and will include @@ -166,7 +147,7 @@ export class Asset extends cdk.Construct implements IAsset { const asset: cxapi.FileAssetMetadataEntry = { path: this.assetPath, id: this.node.uniqueId, - packaging: props.packaging, + packaging, sourceHash: this.sourceHash, s3BucketParameter: bucketParam.logicalId, @@ -221,73 +202,18 @@ export class Asset extends cdk.Construct implements IAsset { } } -export interface FileAssetProps { - /** - * File path. - */ - readonly path: string; - - /** - * A list of principals that should be able to read this file asset from S3. - * You can use `asset.grantRead(principal)` to grant read permissions later. - * - * @default - No principals that can read file asset. - */ - readonly readers?: iam.IGrantable[]; -} - -/** - * An asset that represents a file on disk. - */ -export class FileAsset extends Asset { - constructor(scope: cdk.Construct, id: string, props: FileAssetProps) { - super(scope, id, { packaging: AssetPackaging.File, ...props }); +function determinePackaging(assetPath: string): AssetPackaging { + if (!fs.existsSync(assetPath)) { + throw new Error(`Cannot find asset at ${assetPath}`); } -} -export interface ZipDirectoryAssetProps { - /** - * Path of the directory. - */ - readonly path: string; - - /** - * A list of principals that should be able to read this ZIP file from S3. - * You can use `asset.grantRead(principal)` to grant read permissions later. - * - * @default - No principals that can read file asset. - */ - readonly readers?: iam.IGrantable[]; -} - -/** - * An asset that represents a ZIP archive of a directory on disk. - */ -export class ZipDirectoryAsset extends Asset { - constructor(scope: cdk.Construct, id: string, props: ZipDirectoryAssetProps) { - super(scope, id, { packaging: AssetPackaging.ZipDirectory, ...props }); + if (fs.statSync(assetPath).isDirectory()) { + return AssetPackaging.ZipDirectory; } -} -function validateAssetOnDisk(assetPath: string, packaging: AssetPackaging) { - if (!fs.existsSync(assetPath)) { - throw new Error(`Cannot find asset at ${assetPath}`); + if (fs.statSync(assetPath).isFile()) { + return AssetPackaging.File; } - switch (packaging) { - case AssetPackaging.ZipDirectory: - if (!fs.statSync(assetPath).isDirectory()) { - throw new Error(`${assetPath} is expected to be a directory when asset packaging is 'zip'`); - } - break; - - case AssetPackaging.File: - if (!fs.statSync(assetPath).isFile()) { - throw new Error(`${assetPath} is expected to be a regular file when asset packaging is 'file'`); - } - break; - - default: - throw new Error(`Unsupported asset packaging format: ${packaging}`); - } -} + throw new Error(`Asset ${assetPath} is expected to be either a directory or a regular file`); +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-s3-assets/lib/index.ts b/packages/@aws-cdk/aws-s3-assets/lib/index.ts new file mode 100644 index 0000000000000..ea2719dd83bd3 --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/lib/index.ts @@ -0,0 +1 @@ +export * from './asset'; diff --git a/packages/@aws-cdk/aws-s3-assets/package-lock.json b/packages/@aws-cdk/aws-s3-assets/package-lock.json new file mode 100644 index 0000000000000..140583e4fd6f6 --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/package-lock.json @@ -0,0 +1,150 @@ +{ + "name": "@aws-cdk/aws-s3-assets", + "version": "0.34.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@sinonjs/commons": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.4.0.tgz", + "integrity": "sha512-9jHK3YF/8HtJ9wCAbG+j8cD0i0+ATS9A7gXFqS36TblLPNy6rEEc+SB0imo91eCboGaBYGV/MT1/br/J+EE7Tw==", + "dev": true, + "requires": { + "type-detect": "4.0.8" + } + }, + "@sinonjs/formatio": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.1.tgz", + "integrity": "sha512-tsHvOB24rvyvV2+zKMmPkZ7dXX6LSLKZ7aOtXY6Edklp0uRcgGpOsQTTGTcWViFyx4uhWc6GV8QdnALbIbIdeQ==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1", + "@sinonjs/samsam": "^3.1.0" + } + }, + "@sinonjs/samsam": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.1.tgz", + "integrity": "sha512-wRSfmyd81swH0hA1bxJZJ57xr22kC07a1N4zuIL47yTS04bDk6AoCkczcqHEjcRPmJ+FruGJ9WBQiJwMtIElFw==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.0.2", + "array-from": "^2.1.1", + "lodash": "^4.17.11" + } + }, + "@sinonjs/text-encoding": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", + "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", + "dev": true + }, + "@types/sinon": { + "version": "7.0.12", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-7.0.12.tgz", + "integrity": "sha512-fo0MWpVPSUrnZZhp9wyu+hhI3VJ9+Jhs+PWrokBTg3d2ryNPDOAWF1csIhQuYWBTn7KdZzXpRgpX2o6cwOlPWg==", + "dev": true + }, + "array-from": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", + "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", + "dev": true + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "just-extend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz", + "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==", + "dev": true + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "lolex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.1.0.tgz", + "integrity": "sha512-BYxIEXiVq5lGIXeVHnsFzqa1TxN5acnKnPCdlZSpzm8viNEOhiigupA4vTQ9HEFQ6nLTQ9wQOgBknJgzUYQ9Aw==", + "dev": true + }, + "nise": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.0.tgz", + "integrity": "sha512-Z3sfYEkLFzFmL8KY6xnSJLRxwQwYBjOXi/24lb62ZnZiGA0JUzGGTI6TBIgfCSMIDl9Jlu8SRmHNACLTemDHww==", + "dev": true, + "requires": { + "@sinonjs/formatio": "^3.1.0", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "lolex": "^4.1.0", + "path-to-regexp": "^1.7.0" + } + }, + "path-to-regexp": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", + "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", + "dev": true, + "requires": { + "isarray": "0.0.1" + } + }, + "sinon": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.3.2.tgz", + "integrity": "sha512-thErC1z64BeyGiPvF8aoSg0LEnptSaWE7YhdWWbWXgelOyThent7uKOnnEh9zBxDbKixtr5dEko+ws1sZMuFMA==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.4.0", + "@sinonjs/formatio": "^3.2.1", + "@sinonjs/samsam": "^3.3.1", + "diff": "^3.5.0", + "lolex": "^4.0.1", + "nise": "^1.4.10", + "supports-color": "^5.5.0" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + }, + "ts-mock-imports": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/ts-mock-imports/-/ts-mock-imports-1.2.3.tgz", + "integrity": "sha512-pKeHFhlM4s4LvAPiixTsBTzJ65SY0pcXYFQ6nAmDOHl3lYZk4zi2zZFC3et6xX6tKhCCkt2NaYAY+vciPJlo8Q==", + "dev": true + }, + "type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true + } + } +} diff --git a/packages/@aws-cdk/aws-s3-assets/package.json b/packages/@aws-cdk/aws-s3-assets/package.json new file mode 100644 index 0000000000000..5b3df636893ba --- /dev/null +++ b/packages/@aws-cdk/aws-s3-assets/package.json @@ -0,0 +1,88 @@ +{ + "name": "@aws-cdk/aws-s3-assets", + "version": "0.34.0", + "description": "Deploy local files and directories to S3", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "jsii": { + "outdir": "dist", + "targets": { + "java": { + "package": "software.amazon.awscdk.services.s3.assets", + "maven": { + "groupId": "software.amazon.awscdk", + "artifactId": "s3-assets" + } + }, + "dotnet": { + "namespace": "Amazon.CDK.AWS.S3.Assets", + "packageId": "Amazon.CDK.AWS.S3.Assets", + "signAssembly": true, + "assemblyOriginatorKeyFile": "../../key.snk" + }, + "python": { + "distName": "aws-cdk.aws-s3-assets", + "module": "aws_cdk.aws_s3_assets" + } + } + }, + "repository": { + "type": "git", + "url": "https://github.com/awslabs/aws-cdk.git", + "directory": "packages/@aws-cdk/aws-s3-assets" + }, + "scripts": { + "build": "cdk-build", + "watch": "cdk-watch", + "lint": "cdk-lint", + "test": "cdk-test", + "integ": "cdk-integ", + "pkglint": "pkglint -f", + "package": "cdk-package", + "awslint": "cdk-awslint", + "build+test+package": "npm run build+test && npm run package", + "build+test": "npm run build && npm test" + }, + "keywords": [ + "aws", + "cdk", + "s3", + "constructs", + "assets" + ], + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com", + "organization": true + }, + "license": "Apache-2.0", + "devDependencies": { + "@aws-cdk/assert": "^0.34.0", + "@types/sinon": "^7.0.12", + "aws-cdk": "^0.34.0", + "cdk-build-tools": "^0.34.0", + "cdk-integ-tools": "^0.34.0", + "pkglint": "^0.34.0", + "sinon": "^7.3.2", + "ts-mock-imports": "^1.2.3" + }, + "dependencies": { + "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-iam": "^0.34.0", + "@aws-cdk/aws-s3": "^0.34.0", + "@aws-cdk/cdk": "^0.34.0", + "@aws-cdk/cx-api": "^0.34.0" + }, + "homepage": "https://github.com/awslabs/aws-cdk", + "peerDependencies": { + "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-iam": "^0.34.0", + "@aws-cdk/aws-s3": "^0.34.0", + "@aws-cdk/cdk": "^0.34.0", + "@aws-cdk/cx-api": "^0.34.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "stability": "experimental" +} \ No newline at end of file diff --git a/packages/@aws-cdk/assets/test/file-asset.txt b/packages/@aws-cdk/aws-s3-assets/test/file-asset.txt similarity index 100% rename from packages/@aws-cdk/assets/test/file-asset.txt rename to packages/@aws-cdk/aws-s3-assets/test/file-asset.txt diff --git a/packages/@aws-cdk/assets/test/integ.assets.directory.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.directory.lit.expected.json similarity index 100% rename from packages/@aws-cdk/assets/test/integ.assets.directory.lit.expected.json rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.directory.lit.expected.json diff --git a/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.directory.lit.ts similarity index 88% rename from packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.directory.lit.ts index 38d070cc46110..38f44cb5c8f39 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.directory.lit.ts @@ -8,7 +8,7 @@ class TestStack extends cdk.Stack { super(scope, id, props); /// !show - const asset = new assets.ZipDirectoryAsset(this, 'SampleAsset', { + const asset = new assets.Asset(this, 'SampleAsset', { path: path.join(__dirname, 'sample-asset-directory') }); /// !hide diff --git a/packages/@aws-cdk/assets/test/integ.assets.file.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.file.lit.expected.json similarity index 100% rename from packages/@aws-cdk/assets/test/integ.assets.file.lit.expected.json rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.file.lit.expected.json diff --git a/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.file.lit.ts similarity index 89% rename from packages/@aws-cdk/assets/test/integ.assets.file.lit.ts rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.file.lit.ts index f9d230c6878b9..d9f7469979fbc 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.file.lit.ts @@ -8,7 +8,7 @@ class TestStack extends cdk.Stack { super(scope, id, props); /// !show - const asset = new assets.FileAsset(this, 'SampleAsset', { + const asset = new assets.Asset(this, 'SampleAsset', { path: path.join(__dirname, 'file-asset.txt') }); /// !hide diff --git a/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.permissions.lit.expected.json similarity index 100% rename from packages/@aws-cdk/assets/test/integ.assets.permissions.lit.expected.json rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.permissions.lit.expected.json diff --git a/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.permissions.lit.ts similarity index 90% rename from packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.permissions.lit.ts index 276dfe61f20f4..9b71c1b99c32f 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.permissions.lit.ts @@ -7,7 +7,7 @@ class TestStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); - const asset = new assets.FileAsset(this, 'MyFile', { + const asset = new assets.Asset(this, 'MyFile', { path: path.join(__dirname, 'file-asset.txt') }); diff --git a/packages/@aws-cdk/assets/test/integ.assets.refs.lit.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json similarity index 100% rename from packages/@aws-cdk/assets/test/integ.assets.refs.lit.expected.json rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.expected.json diff --git a/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts similarity index 91% rename from packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts rename to packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts index cbeaf595754e2..5009917681fae 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.assets.refs.lit.ts @@ -8,7 +8,7 @@ class TestStack extends cdk.Stack { super(scope, id, props); /// !show - const asset = new assets.ZipDirectoryAsset(this, 'SampleAsset', { + const asset = new assets.Asset(this, 'SampleAsset', { path: path.join(__dirname, 'sample-asset-directory') }); diff --git a/packages/@aws-cdk/assets/test/integ.multi-assets.expected.json b/packages/@aws-cdk/aws-s3-assets/test/integ.multi-assets.expected.json similarity index 100% rename from packages/@aws-cdk/assets/test/integ.multi-assets.expected.json rename to packages/@aws-cdk/aws-s3-assets/test/integ.multi-assets.expected.json diff --git a/packages/@aws-cdk/assets/test/integ.multi-assets.ts b/packages/@aws-cdk/aws-s3-assets/test/integ.multi-assets.ts similarity index 87% rename from packages/@aws-cdk/assets/test/integ.multi-assets.ts rename to packages/@aws-cdk/aws-s3-assets/test/integ.multi-assets.ts index 214a593700642..57d44d5f7818a 100644 --- a/packages/@aws-cdk/assets/test/integ.multi-assets.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/integ.multi-assets.ts @@ -12,11 +12,11 @@ class TestStack extends cdk.Stack { // Check that the same asset added multiple times is // uploaded and copied. - new assets.FileAsset(this, 'SampleAsset1', { + new assets.Asset(this, 'SampleAsset1', { path: path.join(__dirname, 'file-asset.txt') }); - new assets.FileAsset(this, 'SampleAsset2', { + new assets.Asset(this, 'SampleAsset2', { path: path.join(__dirname, 'file-asset.txt') }); } diff --git a/packages/@aws-cdk/assets/test/sample-asset-directory/sample-asset-file.txt b/packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-asset-file.txt similarity index 100% rename from packages/@aws-cdk/assets/test/sample-asset-directory/sample-asset-file.txt rename to packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-asset-file.txt diff --git a/packages/@aws-cdk/assets/test/sample-asset-directory/sample-jar-asset.jar b/packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-jar-asset.jar similarity index 100% rename from packages/@aws-cdk/assets/test/sample-asset-directory/sample-jar-asset.jar rename to packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-jar-asset.jar diff --git a/packages/@aws-cdk/assets/test/sample-asset-directory/sample-zip-asset.zip b/packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-zip-asset.zip similarity index 100% rename from packages/@aws-cdk/assets/test/sample-asset-directory/sample-zip-asset.zip rename to packages/@aws-cdk/aws-s3-assets/test/sample-asset-directory/sample-zip-asset.zip diff --git a/packages/@aws-cdk/assets/test/test.asset.ts b/packages/@aws-cdk/aws-s3-assets/test/test.asset.ts similarity index 88% rename from packages/@aws-cdk/assets/test/test.asset.ts rename to packages/@aws-cdk/aws-s3-assets/test/test.asset.ts index 5d70326fc14d9..41c4d10611747 100644 --- a/packages/@aws-cdk/assets/test/test.asset.ts +++ b/packages/@aws-cdk/aws-s3-assets/test/test.asset.ts @@ -7,7 +7,7 @@ import fs = require('fs'); import { Test } from 'nodeunit'; import os = require('os'); import path = require('path'); -import { FileAsset, ZipDirectoryAsset } from '../lib/asset'; +import { Asset } from '../lib/asset'; const SAMPLE_ASSET_DIR = path.join(__dirname, 'sample-asset-directory'); @@ -19,7 +19,7 @@ export = { } }); const stack = new cdk.Stack(app, 'MyStack'); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { + const asset = new Asset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); @@ -53,7 +53,7 @@ export = { const stack = new cdk.Stack(app, 'my-stack'); const dirPath = path.resolve(__dirname, 'sample-asset-directory'); - new ZipDirectoryAsset(stack, 'MyAsset', { + new Asset(stack, 'MyAsset', { path: dirPath }); @@ -77,7 +77,7 @@ export = { '"file" assets'(test: Test) { const stack = new cdk.Stack(); const filePath = path.join(__dirname, 'file-asset.txt'); - const asset = new FileAsset(stack, 'MyAsset', { path: filePath }); + const asset = new Asset(stack, 'MyAsset', { path: filePath }); const entry = asset.node.metadata.find(m => m.type === 'aws:cdk:asset'); test.ok(entry, 'found metadata entry'); @@ -106,7 +106,7 @@ export = { const user = new iam.User(stack, 'MyUser'); const group = new iam.Group(stack, 'MyGroup'); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { + const asset = new Asset(stack, 'MyAsset', { path: path.join(__dirname, 'sample-asset-directory'), readers: [ user ] }); @@ -140,7 +140,7 @@ export = { }, 'fails if directory not found'(test: Test) { const stack = new cdk.Stack(); - test.throws(() => new ZipDirectoryAsset(stack, 'MyDirectory', { + test.throws(() => new Asset(stack, 'MyDirectory', { path: '/path/not/found/' + Math.random() * 999999 })); test.done(); @@ -151,8 +151,8 @@ export = { const stack = new cdk.Stack(); // WHEN - new ZipDirectoryAsset(stack, 'MyDirectory1', { path: path.join(__dirname, 'sample-asset-directory') }); - new ZipDirectoryAsset(stack, 'MyDirectory2', { path: path.join(__dirname, 'sample-asset-directory') }); + new Asset(stack, 'MyDirectory1', { path: path.join(__dirname, 'sample-asset-directory') }); + new Asset(stack, 'MyDirectory2', { path: path.join(__dirname, 'sample-asset-directory') }); // THEN: no error @@ -164,19 +164,19 @@ export = { const stack = new cdk.Stack(); // WHEN - const nonZipAsset = new FileAsset(stack, 'NonZipAsset', { + const nonZipAsset = new Asset(stack, 'NonZipAsset', { path: path.join(__dirname, 'sample-asset-directory', 'sample-asset-file.txt') }); - const zipDirectoryAsset = new ZipDirectoryAsset(stack, 'ZipDirectoryAsset', { + const zipDirectoryAsset = new Asset(stack, 'ZipDirectoryAsset', { path: path.join(__dirname, 'sample-asset-directory') }); - const zipFileAsset = new FileAsset(stack, 'ZipFileAsset', { + const zipFileAsset = new Asset(stack, 'ZipFileAsset', { path: path.join(__dirname, 'sample-asset-directory', 'sample-zip-asset.zip') }); - const jarFileAsset = new FileAsset(stack, 'JarFileAsset', { + const jarFileAsset = new Asset(stack, 'JarFileAsset', { path: path.join(__dirname, 'sample-asset-directory', 'sample-jar-asset.jar') }); @@ -195,7 +195,7 @@ export = { const location = path.join(__dirname, 'sample-asset-directory'); const resource = new cdk.CfnResource(stack, 'MyResource', { type: 'My::Resource::Type' }); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { path: location }); + const asset = new Asset(stack, 'MyAsset', { path: location }); // WHEN asset.addResourceMetadata(resource, 'PropName'); @@ -215,7 +215,7 @@ export = { const stack = new cdk.Stack(); const resource = new cdk.CfnResource(stack, 'MyResource', { type: 'My::Resource::Type' }); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); + const asset = new Asset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); // WHEN asset.addResourceMetadata(resource, 'PropName'); @@ -242,11 +242,11 @@ export = { const stack = new Stack(app, 'stack'); // WHEN - new FileAsset(stack, 'ZipFile', { + new Asset(stack, 'ZipFile', { path: path.join(SAMPLE_ASSET_DIR, 'sample-zip-asset.zip') }); - new FileAsset(stack, 'TextFile', { + new Asset(stack, 'TextFile', { path: path.join(SAMPLE_ASSET_DIR, 'sample-asset-file.txt') }); @@ -266,7 +266,7 @@ export = { const stack = new Stack(app, 'stack'); // WHEN - new ZipDirectoryAsset(stack, 'ZipDirectory', { + new Asset(stack, 'ZipDirectory', { path: SAMPLE_ASSET_DIR }); @@ -296,7 +296,7 @@ export = { const stack = new Stack(app, 'stack'); const resource = new cdk.CfnResource(stack, 'MyResource', { type: 'My::Resource::Type' }); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); + const asset = new Asset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); // WHEN asset.addResourceMetadata(resource, 'PropName'); @@ -323,7 +323,7 @@ export = { const stack = new Stack(app, 'stack'); const resource = new cdk.CfnResource(stack, 'MyResource', { type: 'My::Resource::Type' }); - const asset = new ZipDirectoryAsset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); + const asset = new Asset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); // WHEN asset.addResourceMetadata(resource, 'PropName'); @@ -340,7 +340,7 @@ export = { // GIVEN const app = new App(); const stack = new Stack(app, 'stack'); - new ZipDirectoryAsset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); + new Asset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR }); // WHEN const session = app.synth(); diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index 77c427abfb8a3..4514758cbe124 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -45,7 +45,7 @@ export class BucketDeployment extends cdk.Construct { const handler = new lambda.SingletonFunction(this, 'CustomResourceHandler', { uuid: '8693BB64-9689-44B6-9AAF-B0CC9EB8756C', - code: lambda.Code.file(handlerCodeBundle), + code: lambda.Code.asset(handlerCodeBundle), runtime: lambda.Runtime.Python36, handler: 'index.handler', lambdaPurpose: 'Custom::CDKBucketDeployment', diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/source.ts b/packages/@aws-cdk/aws-s3-deployment/lib/source.ts index cdd2fd13b1c7b..8d8fe0d3016bc 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/source.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/source.ts @@ -1,7 +1,6 @@ -import assets = require('@aws-cdk/assets'); import s3 = require('@aws-cdk/aws-s3'); +import s3_assets = require('@aws-cdk/aws-s3-assets'); import cdk = require('@aws-cdk/cdk'); -import fs = require('fs'); export interface SourceConfig { /** @@ -55,8 +54,7 @@ export class Source { public static asset(path: string): ISource { return { bind(context: cdk.Construct): SourceConfig { - const packaging = fs.lstatSync(path).isDirectory() ? assets.AssetPackaging.ZipDirectory : assets.AssetPackaging.File; - const asset = new assets.Asset(context, 'Asset', { packaging, path }); + const asset = new s3_assets.Asset(context, 'Asset', { path }); if (!asset.isZipArchive) { throw new Error(`Asset path must be either a .zip file or a directory`); } diff --git a/packages/@aws-cdk/aws-s3-deployment/package.json b/packages/@aws-cdk/aws-s3-deployment/package.json index e34d75b72d626..5b9e896cdf9ff 100644 --- a/packages/@aws-cdk/aws-s3-deployment/package.json +++ b/packages/@aws-cdk/aws-s3-deployment/package.json @@ -80,7 +80,7 @@ "pkglint": "^0.34.0" }, "dependencies": { - "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/aws-cloudformation": "^0.34.0", "@aws-cdk/aws-iam": "^0.34.0", "@aws-cdk/aws-lambda": "^0.34.0", @@ -89,7 +89,7 @@ }, "homepage": "https://github.com/awslabs/aws-cdk", "peerDependencies": { - "@aws-cdk/assets": "^0.34.0", + "@aws-cdk/aws-s3-assets": "^0.34.0", "@aws-cdk/aws-cloudformation": "^0.34.0", "@aws-cdk/aws-iam": "^0.34.0", "@aws-cdk/aws-lambda": "^0.34.0", diff --git a/packages/decdk/package.json b/packages/decdk/package.json index 3e18a459834ea..50dd46ca790ce 100644 --- a/packages/decdk/package.json +++ b/packages/decdk/package.json @@ -30,7 +30,6 @@ "@aws-cdk/alexa-ask": "^0.34.0", "@aws-cdk/app-delivery": "^0.34.0", "@aws-cdk/assets": "^0.34.0", - "@aws-cdk/assets-docker": "^0.34.0", "@aws-cdk/aws-amazonmq": "^0.34.0", "@aws-cdk/aws-amplify": "^0.34.0", "@aws-cdk/aws-apigateway": "^0.34.0", @@ -142,7 +141,9 @@ "jsii-reflect": "^0.11.2", "jsonschema": "^1.2.4", "yaml": "1.6.0", - "yargs": "^13.2.4" + "yargs": "^13.2.4", + "@aws-cdk/aws-ecr-assets": "^0.34.0", + "@aws-cdk/aws-s3-assets": "^0.34.0" }, "devDependencies": { "@types/fs-extra": "^7.0.0",