From f764bfb53b34c3cbf55ce47e510e2309d0f38103 Mon Sep 17 00:00:00 2001 From: WinterYukky <49480575+WinterYukky@users.noreply.github.com> Date: Fri, 31 Mar 2023 04:50:21 +0900 Subject: [PATCH] docs(s3-assets): fix the doc to compilable (#24864) ## Summary `aws-s3-assets` doc has typo and not compilable, so I fixed it. ![image](https://user-images.githubusercontent.com/49480575/228748321-8746830e-f7e7-42d3-836b-1d60b1f46c20.png) Closes #. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-s3-assets/README.md | 24 ++++++++++++------- .../aws-s3-assets/rosetta/default.ts-fixture | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md index b14612f967121..d9044b045bb73 100644 --- a/packages/@aws-cdk/aws-s3-assets/README.md +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -95,8 +95,10 @@ method `tryBundle()` which should return `true` if local bundling was performed. If `false` is returned, docker bundling will be done: ```ts -class MyBundle implements ILocalBundling { - public tryBundle(outputDir: string, options: BundlingOptions) { +import * as cdk from '@aws-cdk/core'; + +class MyBundle implements cdk.ILocalBundling { + public tryBundle(outputDir: string, options: cdk.BundlingOptions) { const canRunLocally = true // replace with actual logic if (canRunLocally) { // perform local bundling here @@ -106,12 +108,12 @@ class MyBundle implements ILocalBundling { } } -new assets.Asset(this, 'BundledAsset', { +new Asset(this, 'BundledAsset', { path: '/path/to/asset', bundling: { local: new MyBundle(), // Docker bundling fallback - image: DockerImage.fromRegistry('alpine'), + image: cdk.DockerImage.fromRegistry('alpine'), entrypoint: ['/bin/sh', '-c'], command: ['bundle'], }, @@ -129,12 +131,14 @@ is the default behavior for `bundling.outputType` (`BundlingOutput.AUTO_DISCOVER Use `BundlingOutput.NOT_ARCHIVED` if the bundling output must always be zipped: ```ts -const asset = new assets.Asset(this, 'BundledAsset', { +import * as cdk from '@aws-cdk/core'; + +const asset = new Asset(this, 'BundledAsset', { path: '/path/to/asset', bundling: { - image: DockerImage.fromRegistry('alpine'), + image: cdk.DockerImage.fromRegistry('alpine'), command: ['command-that-produces-an-archive.sh'], - outputType: BundlingOutput.NOT_ARCHIVED, // Bundling output will be zipped even though it produces a single archive file. + outputType: cdk.BundlingOutput.NOT_ARCHIVED, // Bundling output will be zipped even though it produces a single archive file. }, }); ``` @@ -150,10 +154,12 @@ This can be done using [BundlingOptions](https://docs.aws.amazon.com/cdk/api/v2/ Some optional properties to pass to the docker bundling ```ts -const asset = new assets.Asset(this, 'BundledAsset', { +import * as lambda from '@aws-cdk/aws-lambda'; + +const asset = new Asset(this, 'BundledAsset', { path: '/path/to/asset', bundling: { - image: ambda.Runtime.PYTHON_3_9.bundlingImage,, + image: lambda.Runtime.PYTHON_3_9.bundlingImage, command: [ 'bash', '-c', 'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output' diff --git a/packages/@aws-cdk/aws-s3-assets/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-s3-assets/rosetta/default.ts-fixture index 52f4c907d8b07..b537eeb882c64 100644 --- a/packages/@aws-cdk/aws-s3-assets/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-s3-assets/rosetta/default.ts-fixture @@ -1,7 +1,7 @@ // Fixture with packages imported, but nothing else import { Construct } from 'constructs'; -import { BundlingOptions, BundlingOutput, DockerImage, ILocalBundling, Stack } from '@aws-cdk/core'; -import * as assets from '@aws-cdk/aws-s3-assets'; +import { Stack } from '@aws-cdk/core'; +import { Asset } from '@aws-cdk/aws-s3-assets'; class Fixture extends Stack { constructor(scope: Construct, id: string) {