Skip to content

Commit

Permalink
Merge branch 'main' of github.com:aws/aws-cdk into feat/repo-restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
MrArnoldPalmer committed Mar 30, 2023
2 parents 85d828f + f764bfb commit b97eb78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions packages/@aws-cdk/aws-s3-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
},
Expand All @@ -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.
},
});
```
Expand All @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-s3-assets/rosetta/default.ts-fixture
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit b97eb78

Please sign in to comment.