class InfrastructureConfiguration (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.ImageBuilder.Alpha.InfrastructureConfiguration |
Go | github.com/aws/aws-cdk-go/awsimagebuilderalpha/v2#InfrastructureConfiguration |
Java | software.amazon.awscdk.services.imagebuilder.alpha.InfrastructureConfiguration |
Python | aws_cdk.aws_imagebuilder_alpha.InfrastructureConfiguration |
TypeScript (source) | @aws-cdk/aws-imagebuilder-alpha ยป InfrastructureConfiguration |
Implements
IConstruct, IDependable, IResource, IEnvironment, IInfrastructure
Represents an EC2 Image Builder Infrastructure Configuration.
See also: https://docs.aws.amazon.com/imagebuilder/latest/userguide/manage-infra-config.html
Example
const infrastructureConfiguration = new imagebuilder.InfrastructureConfiguration(this, 'InfrastructureConfiguration', {
infrastructureConfigurationName: 'test-infrastructure-configuration',
description: 'An Infrastructure Configuration',
// Optional - instance types to use for build/test
instanceTypes: [
ec2.InstanceType.of(ec2.InstanceClass.STANDARD7_INTEL, ec2.InstanceSize.LARGE),
ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.LARGE)
],
// Optional - create an instance profile with necessary permissions
instanceProfile: new iam.InstanceProfile(this, 'InstanceProfile', {
instanceProfileName: 'test-instance-profile',
role: new iam.Role(this, 'InstanceProfileRole', {
assumedBy: iam.ServicePrincipal.fromStaticServicePrincipleName('ec2.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMManagedInstanceCore'),
iam.ManagedPolicy.fromAwsManagedPolicyName('EC2InstanceProfileForImageBuilder')
]
})
}),
// Use VPC network configuration
vpc,
subnetSelection: { subnetType: ec2.SubnetType.PUBLIC },
securityGroups: [ec2.SecurityGroup.fromSecurityGroupId(this, 'SecurityGroup', vpc.vpcDefaultSecurityGroup)],
keyPair: ec2.KeyPair.fromKeyPairName(this, 'KeyPair', 'imagebuilder-instance-key-pair'),
terminateInstanceOnFailure: true,
// Optional - IMDSv2 settings
httpTokens: imagebuilder.HttpTokens.REQUIRED,
httpPutResponseHopLimit: 1,
// Optional - publish image completion messages to an SNS topic
notificationTopic: sns.Topic.fromTopicArn(
this,
'Topic',
this.formatArn({ service: 'sns', resource: 'image-builder-topic' })
),
// Optional - log settings. Logging is enabled by default
logging: {
s3Bucket: s3.Bucket.fromBucketName(this, 'LogBucket', `imagebuilder-logging-${Aws.ACCOUNT_ID}`),
s3KeyPrefix: 'imagebuilder-logs'
},
// Optional - host placement settings
ec2InstanceAvailabilityZone: Stack.of(this).availabilityZones[0],
ec2InstanceHostId: dedicatedHost.attrHostId,
ec2InstanceTenancy: imagebuilder.Tenancy.HOST,
resourceTags: {
Environment: 'production'
}
});
Initializer
new InfrastructureConfiguration(scope: Construct, id: string, props?: InfrastructureConfigurationProps)
Parameters
- scope
Construct - id
string - props
InfrastructureConfiguration Props
Construct Props
| Name | Type | Description |
|---|---|---|
| description? | string | The description of the infrastructure configuration. |
| ec2 | string | The availability zone to place Image Builder build and test EC2 instances. |
| ec2 | string | The ID of the Dedicated Host on which build and test instances run. |
| ec2 | string | The ARN of the host resource group on which build and test instances run. |
| ec2 | Tenancy | The tenancy of the instance. |
| http | number | The maximum number of hops that an instance metadata request can traverse to reach its destination. |
| http | Http | Indicates whether a signed token header is required for instance metadata retrieval requests. |
| infrastructure | string | The name of the infrastructure configuration. |
| instance | IInstance | The instance profile to associate with the instance used to customize the AMI. |
| instance | Instance[] | The instance types to launch build and test EC2 instances with. |
| key | IKey | The key pair used to connect to the build and test EC2 instances. |
| logging? | Infrastructure | The log settings for detailed build logging. |
| notification | ITopic | The SNS topic on which notifications are sent when an image build completes. |
| resource | { [string]: string } | The additional tags to assign to the Amazon EC2 instance that Image Builder launches during the build process. |
| role? | IRole | An IAM role to associate with the instance profile used by Image Builder. |
| security | ISecurity[] | The security groups to associate with the instance used to customize the AMI. |
| subnet | Subnet | Select which subnet to place the instance used to customize the AMI. |
| tags? | { [string]: string } | The tags to apply to the infrastructure configuration. |
| terminate | boolean | Whether to terminate the EC2 instance when the build or test workflow fails. |
| vpc? | IVpc | The VPC to place the instance used to customize the AMI. |
description?
Type:
string
(optional, default: None)
The description of the infrastructure configuration.
ec2InstanceAvailabilityZone?
Type:
string
(optional, default: EC2 will select a random zone)
The availability zone to place Image Builder build and test EC2 instances.
ec2InstanceHostId?
Type:
string
(optional, default: None)
The ID of the Dedicated Host on which build and test instances run.
This only applies if the instance tenancy is
host. This cannot be used with the ec2InstanceHostResourceGroupArn parameter.
ec2InstanceHostResourceGroupArn?
Type:
string
(optional, default: None)
The ARN of the host resource group on which build and test instances run.
This only applies if the instance tenancy
is host. This cannot be used with the ec2InstanceHostId parameter.
ec2InstanceTenancy?
Type:
Tenancy
(optional, default: Tenancy.DEFAULT)
The tenancy of the instance.
Dedicated tenancy runs instances on single-tenant hardware, while host tenancy runs instances on a dedicated host. Shared tenancy is used by default.
httpPutResponseHopLimit?
Type:
number
(optional, default: 2)
The maximum number of hops that an instance metadata request can traverse to reach its destination.
By default, this is set to 2.
httpTokens?
Type:
Http
(optional, default: HttpTokens.REQUIRED)
Indicates whether a signed token header is required for instance metadata retrieval requests.
By default, this is
set to required to require IMDSv2 on build and test EC2 instances.
infrastructureConfigurationName?
Type:
string
(optional, default: A name is generated)
The name of the infrastructure configuration.
This name must be normalized by transforming all alphabetical characters to lowercase, and replacing all spaces and underscores with hyphens.
instanceProfile?
Type:
IInstance
(optional, default: An instance profile will be generated)
The instance profile to associate with the instance used to customize the AMI.
By default, an instance profile and role will be created with minimal permissions needed to build the image, attached to the EC2 instance.
If an S3 logging bucket and key prefix is provided, an IAM inline policy will be attached to the instance profile's role, allowing s3:PutObject permissions on the bucket.
instanceTypes?
Type:
Instance[]
(optional, default: Image Builder will choose from a default set of instance types compatible with the AMI)
The instance types to launch build and test EC2 instances with.
keyPair?
Type:
IKey
(optional, default: None)
The key pair used to connect to the build and test EC2 instances.
The key pair can be used to log into the build or test instances for troubleshooting any failures.
logging?
Type:
Infrastructure
(optional, default: None)
The log settings for detailed build logging.
notificationTopic?
Type:
ITopic
(optional, default: No notifications are sent)
The SNS topic on which notifications are sent when an image build completes.
resourceTags?
Type:
{ [string]: string }
(optional, default: None)
The additional tags to assign to the Amazon EC2 instance that Image Builder launches during the build process.
role?
Type:
IRole
(optional, default: A role will automatically be created, it can be accessed via the role property)
An IAM role to associate with the instance profile used by Image Builder.
The role must be assumable by the service principal ec2.amazonaws.com:
Note: You can provide an instanceProfile or a role, but not both.
Example
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
securityGroups?
Type:
ISecurity[]
(optional, default: The default security group for the VPC will be used)
The security groups to associate with the instance used to customize the AMI.
subnetSelection?
Type:
Subnet
(optional, default: The first subnet selected from the provided VPC will be used)
Select which subnet to place the instance used to customize the AMI.
The first subnet that is selected will be used. You must specify the VPC to customize the subnet selection.
tags?
Type:
{ [string]: string }
(optional, default: None)
The tags to apply to the infrastructure configuration.
terminateInstanceOnFailure?
Type:
boolean
(optional, default: true)
Whether to terminate the EC2 instance when the build or test workflow fails.
vpc?
Type:
IVpc
(optional, default: The default VPC will be used)
The VPC to place the instance used to customize the AMI.
Properties
| Name | Type | Description |
|---|---|---|
| env | Resource | The environment this resource belongs to. |
| infrastructure | string | The ARN of the infrastructure configuration. |
| infrastructure | string | The name of the infrastructure configuration. |
| instance | IInstance | The EC2 instance profile to use for the build. |
| node | Node | The tree node. |
| stack | Stack | The stack in which this resource is defined. |
| log | IBucket | The bucket used to upload image build logs. |
| role? | IRole | The role associated with the EC2 instance profile used for the build. |
| static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed in a Stack (those created by
creating new class instances like new Role(), new Bucket(), etc.), this
is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like
Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be
different than the stack they were imported into.
infrastructureConfigurationArn
Type:
string
The ARN of the infrastructure configuration.
infrastructureConfigurationName
Type:
string
The name of the infrastructure configuration.
instanceProfile
Type:
IInstance
The EC2 instance profile to use for the build.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
logBucket?
Type:
IBucket
(optional)
The bucket used to upload image build logs.
role?
Type:
IRole
(optional)
The role associated with the EC2 instance profile used for the build.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
| Name | Description |
|---|---|
| apply | Apply the given removal policy to this resource. |
| grant(grantee, ...actions) | Grant custom actions to the given grantee for the infrastructure configuration. |
| grant | Grant read permissions to the given grantee for the infrastructure configuration. |
| to | Returns a string representation of this construct. |
| static from | Import an existing infrastructure configuration given its ARN. |
| static from | Import an existing infrastructure configuration given its name. |
| static is | Return whether the given object is an InfrastructureConfiguration. |
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
RemovalPolicy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantableโ - The principal. - actions
stringโ - The list of actions.
Returns
Grant custom actions to the given grantee for the infrastructure configuration.
grantRead(grantee)
public grantRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The principal.
Returns
Grant read permissions to the given grantee for the infrastructure configuration.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromInfrastructureConfigurationArn(scope, id, infrastructureConfigurationArn)
public static fromInfrastructureConfigurationArn(scope: Construct, id: string, infrastructureConfigurationArn: string): IInfrastructureConfiguration
Parameters
- scope
Construct - id
string - infrastructureConfigurationArn
string
Returns
Import an existing infrastructure configuration given its ARN.
static fromInfrastructureConfigurationName(scope, id, infrastructureConfigurationName)
public static fromInfrastructureConfigurationName(scope: Construct, id: string, infrastructureConfigurationName: string): IInfrastructureConfiguration
Parameters
- scope
Construct - id
string - infrastructureConfigurationName
string
Returns
Import an existing infrastructure configuration given its name.
The provided name must be normalized by converting all alphabetical characters to lowercase, and replacing all spaces and underscores with hyphens.
static isInfrastructureConfiguration(x)
public static isInfrastructureConfiguration(x: any): boolean
Parameters
- x
any
Returns
boolean
Return whether the given object is an InfrastructureConfiguration.

.NET
Go
Java
Python
TypeScript (