Skip to main content

Creates an EC2 AMI using an Image Builder Pipeline and returns the AMI ID.

Project description

ImagePipeline Construct for AWS CDK

Overview

The ImagePipeline construct is a versatile and powerful component of the AWS Cloud Development Kit (CDK) designed for creating and managing AWS Image Builder pipelines. This construct simplifies the process of setting up automated pipelines for building and maintaining Amazon Machine Images (AMIs). It provides extensive customization options, enabling users to tailor the pipeline to specific needs, including vulnerability scanning, cross-account distribution, and more.

Benefits

  1. Customizable Image Building: Offers a wide range of parameters to customize the AMI, including VPC settings, security groups, instance types, and more.
  2. Automated Pipeline Management: Automates the pipeline creation and execution process, reducing manual effort and potential errors.
  3. Cross-Account AMI Distribution: Facilitates the copying of AMIs to multiple AWS accounts, enhancing resource sharing and collaboration.
  4. Vulnerability Scanning Integration: Supports integration with AWS Inspector for continuous vulnerability scanning, ensuring security compliance.
  5. User-Friendly: Designed with user experience in mind, making it easy to integrate into AWS CDK projects.
  6. Scalability and Flexibility: Scales according to your needs and provides flexibility in configuring various aspects of the image building process.

Prerequisites

  • AWS account and AWS CLI configured.
  • Familiarity with AWS CDK and TypeScript.
  • Node.js and npm installed.

Installation

Ensure that you have the AWS CDK installed. If not, you can install it using npm:

npm install -g aws-cdk

Next, add the ImagePipeline construct to your CDK project:

npm install '@jjrawlins/cdk-ami-builder' --save

Usage Example

Below is an example of how to use the ImagePipeline construct in your CDK application.

Importing the Construct

First, import the ImagePipeline construct into your CDK application:

import { ImagePipeline } from '@jjrawlins/cdk-ami-builder';

Using the Construct

Here's an example of how to use the ImagePipeline construct:

const vpc = new Vpc(this, 'Vpc', {
    ipAddresses: IpAddresses.cidr(props.vpcCidr as string),
    maxAzs: 2,
    subnetConfiguration: [
        {
            name: 'Public',
            subnetType: SubnetType.PUBLIC,
            cidrMask: 24,
        },
        {
            name: 'Private',
            subnetType: SubnetType.PRIVATE_WITH_EGRESS,
            cidrMask: 24,
        },
    ],
    natGateways: 1,
});

const image = ec2.MachineImage.lookup({
    name: 'ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*',
    owners: ['099720109477'],
});

const version = process.env.IMAGE_VERSION_NUMBER ?? '0.0.8';

const imagePipeline = new ImagePipeline(this, 'ImagePipeline', {
    parentImage: image.getImage(this).imageId,
    vpc: vpc,
    imageRecipeVersion: version,
    components: [
        {
            name: 'Install-Monitoring',
            platform: 'Linux',
            componentDocument: {
                phases: [{
                    name: 'build',
                    steps: [
                        {
                            name: 'Install-CloudWatch-Agent',
                            action: 'ExecuteBash',
                            inputs: {
                                commands: [
                                    'apt-get update',
                                    'DEBIAN_FRONTEND=noninteractive apt-get install -y g++ make cmake unzip libcur14-openssl-dev',
                                    'DEBIAN_FRONTEND=noninteractive apt-get install -y curl sudo jq bash zip unzip iptables software-properties-common ca-certificates',
                                    'curl -sfLo /tmp/amazon-cloudwatch-agent.deb https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb',
                                    'dpkg -i -E /tmp/amazon-cloudwatch-agent.deb',
                                    'rm /tmp/amazon-cloudwatch-agent.deb',
                                ],
                            },
                        },
                    ],
                }],
            },
        },
    ],
});

new CfnOutput(this, `ImageId-${this.stackName}`, {
    value: imagePipeline.imageId,  // Only valid if autoBuild=true
    description: 'The AMI ID of the image created by the pipeline',
});

This example demonstrates creating a new VPC and setting up an Image Pipeline within it. You can customize the `

ImagePipeline` properties according to your requirements.

Customization Options

  • vpc: Specify the VPC where the Image Pipeline will be deployed.
  • parentImage: Define the base AMI for the image recipe.
  • components: List custom components for the AMI, such as software installations and configurations.
  • Additional properties like imageRecipeVersion, platform, enableVulnScans, etc., allow further customization.

Outputs

The construct provides outputs like imagePipelineArn and imageId, which can be used in other parts of your AWS infrastructure setup.

Best Practices

  1. Parameter Validation: Ensure that all inputs to the construct are validated.
  2. Security: Follow best practices for security group and IAM role configurations.
  3. Resource Naming: Use meaningful names for resources for better manageability.
  4. Error Handling: Implement error handling for pipeline execution and custom resources.

Support and Contribution

For support, please contact the package maintainer or open an issue in the repository. Contributions to the package are welcome. Please follow the contribution guidelines in the repository.


This README provides a basic guide to getting started with the ImagePipeline construct. For more advanced usage and customization, refer to the detailed documentation in the package.

User

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jjrawlins_cdk_ami_builder-0.0.89.tar.gz (6.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jjrawlins_cdk_ami_builder-0.0.89-py3-none-any.whl (6.0 MB view details)

Uploaded Python 3

File details

Details for the file jjrawlins_cdk_ami_builder-0.0.89.tar.gz.

File metadata

File hashes

Hashes for jjrawlins_cdk_ami_builder-0.0.89.tar.gz
Algorithm Hash digest
SHA256 758b6f4b10fd4cd258249eaec1b89e637b0bcd2b2fd98190a9f04e0fda3a87a7
MD5 093ae07e36c08469fca93babcae7e676
BLAKE2b-256 19bb35ed28ca49101598971169e3ae07a993fa8f6476b647213454f20053915a

See more details on using hashes here.

File details

Details for the file jjrawlins_cdk_ami_builder-0.0.89-py3-none-any.whl.

File metadata

File hashes

Hashes for jjrawlins_cdk_ami_builder-0.0.89-py3-none-any.whl
Algorithm Hash digest
SHA256 65c4812813cc1223c58bcd3450ef602917cfe0a36bc3f533dffe760f0b00c76f
MD5 96f05ff817d677d487d842e2490d435a
BLAKE2b-256 b4be89d328fe83631ecc39454b73b286d7bb3ffe20fa49c841d62ead7de97722

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page