Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions packages/@aws-cdk/aws-imagebuilder-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,210 @@ EC2 Image Builder supports AWS-managed components for common tasks, AWS Marketpl
that you create. Components run during specific workflow phases: build and validate phases during the build stage, and
test phase during the test stage.

### Component

A component defines the sequence of steps required to customize an instance during image creation (build component) or
test an instance launched from the created image (test component). Components are created from declarative YAML or JSON
documents that describe runtime configuration for building, validating, or testing instances. Components are included
when added to the image recipe or container recipe for an image build.

EC2 Image Builder supports AWS-managed components for common tasks, AWS Marketplace components, and custom components
that you create. Components run during specific workflow phases: build and validate phases during the build stage, and
test phase during the test stage.

#### Basic Usage

Create a component with the required properties: platform and component data.

```ts
const component = new imagebuilder.Component(this, 'MyComponent', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromJsonObject({
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
phases: [
{
name: imagebuilder.ComponentPhaseName.BUILD,
steps: [
{
name: 'install-app',
action: imagebuilder.ComponentAction.EXECUTE_BASH,
inputs: {
commands: ['echo "Installing my application..."', 'yum update -y'],
},
},
],
},
],
}),
});
```

#### Component Data Sources

##### Inline Component Data

Use `ComponentData.fromInline()` for existing YAML/JSON definitions:

```ts
const component = new imagebuilder.Component(this, 'InlineComponent', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromInline(`
name: my-component
schemaVersion: 1.0
phases:
- name: build
steps:
- name: update-os
action: ExecuteBash
inputs:
commands: ['yum update -y']
`)
});
```

##### JSON Object Component Data

Most developer-friendly approach using objects:

```ts
const component = new imagebuilder.Component(this, 'JsonComponent', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromJsonObject({
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
phases: [
{
name: imagebuilder.ComponentPhaseName.BUILD,
steps: [
{
name: 'configure-app',
action: imagebuilder.ComponentAction.CREATE_FILE,
inputs: {
path: '/etc/myapp/config.json',
content: '{"env": "production"}',
},
},
],
},
],
}),
});
```

##### Structured Component Document

For type-safe, CDK-native definitions with enhanced properties like `timeout` and `onFailure`:

```ts
const component = new imagebuilder.Component(this, 'StructuredComponent', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromComponentDocumentJsonObject({
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
phases: [
{
name: imagebuilder.ComponentPhaseName.BUILD,
steps: [
{
name: 'install-with-timeout',
action: imagebuilder.ComponentAction.EXECUTE_BASH,
timeout: Duration.minutes(10),
onFailure: imagebuilder.ComponentOnFailure.CONTINUE,
inputs: {
commands: ['./install-script.sh'],
},
},
],
},
],
}),
});
```

##### S3 Component Data

For those components you want to upload or have uploaded to S3:

```ts
// Upload a local file
const componentFromAsset = new imagebuilder.Component(this, 'AssetComponent', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromAsset(this, 'ComponentAsset', './my-component.yml'),
});

// Reference an existing S3 object
const bucket = s3.Bucket.fromBucketName(this, 'ComponentBucket', 'my-components-bucket');
const componentFromS3 = new imagebuilder.Component(this, 'S3Component', {
platform: imagebuilder.Platform.LINUX,
data: imagebuilder.ComponentData.fromS3(bucket, 'components/my-component.yml'),
});
```

#### Encrypt component data with a KMS key

You can encrypt component data with a KMS key, so that only principals with access to decrypt with the key are able to
access the component data.

```ts
const component = new imagebuilder.Component(this, 'EncryptedComponent', {
platform: imagebuilder.Platform.LINUX,
kmsKey: new kms.Key(this, 'ComponentKey'),
data: imagebuilder.ComponentData.fromJsonObject({
schemaVersion: imagebuilder.ComponentSchemaVersion.V1_0,
phases: [
{
name: imagebuilder.ComponentPhaseName.BUILD,
steps: [
{
name: 'secure-setup',
action: imagebuilder.ComponentAction.EXECUTE_BASH,
inputs: {
commands: ['echo "This component data is encrypted with KMS"'],
},
},
],
},
],
}),
});
```

#### AWS-Managed Components

AWS provides a collection of managed components for common tasks:

```ts
// Install AWS CLI v2
const awsCliComponent = imagebuilder.AwsManagedComponent.awsCliV2(this, 'AwsCli', {
platform: imagebuilder.Platform.LINUX
});

// Update the operating system
const updateComponent = imagebuilder.AwsManagedComponent.updateOS(this, 'UpdateOS', {
platform: imagebuilder.Platform.LINUX
});

// Reference any AWS-managed component by name
const customAwsComponent = imagebuilder.AwsManagedComponent.fromAwsManagedComponentName(
this,
'CloudWatchAgent',
'amazon-cloudwatch-agent-linux'
);
```

#### AWS Marketplace Components

You can reference AWS Marketplace components using the marketplace component name and its product ID:

```ts
const marketplaceComponent = imagebuilder.AwsMarketplaceComponent.fromAwsMarketplaceComponentAttributes(
this,
'MarketplaceComponent',
{
componentName: 'my-marketplace-component',
marketplaceProductId: 'prod-1234567890abcdef0',
}
);
```

### Infrastructure Configuration

Infrastructure configuration defines the compute resources and environment settings used during the image building
Expand Down
Loading
Loading