@@ -94,7 +94,7 @@ export interface InfrastructureConfigurationLogging {
9494 /**
9595 * The S3 logging prefix to use for detailed build logging
9696 *
97- * @default - No prefix
97+ * @default No prefix
9898 */
9999 readonly s3KeyPrefix ?: string ;
100100}
@@ -107,21 +107,21 @@ export interface InfrastructureConfigurationProps {
107107 * The name of the infrastructure configuration. This name must be normalized by transforming all alphabetical
108108 * characters to lowercase, and replacing all spaces and underscores with hyphens.
109109 *
110- * @default - A name is generated
110+ * @default A name is generated
111111 */
112112 readonly infrastructureConfigurationName ?: string ;
113113
114114 /**
115115 * The description of the infrastructure configuration.
116116 *
117- * @default - None
117+ * @default None
118118 */
119119 readonly description ?: string ;
120120
121121 /**
122122 * The instance types to launch build and test EC2 instances with.
123123 *
124- * @default - Image Builder will choose from a default set of instance types compatible with the AMI
124+ * @default Image Builder will choose from a default set of instance types compatible with the AMI
125125 */
126126 readonly instanceTypes ?: ec2 . InstanceType [ ] ;
127127
@@ -134,7 +134,7 @@ export interface InfrastructureConfigurationProps {
134134 * If an S3 logging bucket and key prefix is provided, an IAM inline policy will be attached to the instance profile's
135135 * role, allowing s3:PutObject permissions on the bucket.
136136 *
137- * @default - An instance profile will be generated
137+ * @default An instance profile will be generated
138138 */
139139 readonly instanceProfile ?: iam . IInstanceProfile ;
140140 /**
@@ -148,119 +148,119 @@ export interface InfrastructureConfigurationProps {
148148 * assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
149149 * });
150150 *
151- * @default - A role will automatically be created, it can be accessed via the `role` property
151+ * @default A role will automatically be created, it can be accessed via the `role` property
152152 */
153153 readonly role ?: iam . IRole ;
154154
155155 /**
156156 * The VPC to place the instance used to customize the AMI.
157157 *
158- * @default - The default VPC will be used
158+ * @default The default VPC will be used
159159 */
160160 readonly vpc ?: ec2 . IVpc ;
161161
162162 /**
163163 * Select which subnet to place the instance used to customize the AMI. The first subnet that is selected will be used.
164164 * You must specify the VPC to customize the subnet selection.
165165 *
166- * @default - The first subnet selected from the provided VPC will be used
166+ * @default The first subnet selected from the provided VPC will be used
167167 */
168168 readonly subnetSelection ?: ec2 . SubnetSelection ;
169169
170170 /**
171171 * The security groups to associate with the instance used to customize the AMI.
172172 *
173- * @default - The default security group for the VPC will be used
173+ * @default The default security group for the VPC will be used
174174 */
175175 readonly securityGroups ?: ec2 . ISecurityGroup [ ] ;
176176
177177 /**
178178 * The key pair used to connect to the build and test EC2 instances. The key pair can be used to log into the build
179179 * or test instances for troubleshooting any failures.
180180 *
181- * @default - None
181+ * @default None
182182 */
183183 readonly keyPair ?: ec2 . IKeyPair ;
184184
185185 /**
186186 * Whether to terminate the EC2 instance when the build or test workflow fails.
187187 *
188- * @default - true
188+ * @default true
189189 */
190190 readonly terminateInstanceOnFailure ?: boolean ;
191191
192192 /**
193193 * The maximum number of hops that an instance metadata request can traverse to reach its destination. By default,
194194 * this is set to 2.
195195 *
196- * @default - 2
196+ * @default 2
197197 */
198198 readonly httpPutResponseHopLimit ?: number ;
199199
200200 /**
201201 * Indicates whether a signed token header is required for instance metadata retrieval requests. By default, this is
202202 * set to `required` to require IMDSv2 on build and test EC2 instances.
203203 *
204- * @default - HttpTokens.REQUIRED
204+ * @default HttpTokens.REQUIRED
205205 */
206206 readonly httpTokens ?: HttpTokens ;
207207
208208 /**
209209 * The SNS topic on which notifications are sent when an image build completes.
210210 *
211- * @default - No notifications are sent
211+ * @default No notifications are sent
212212 */
213213 readonly notificationTopic ?: sns . ITopic ;
214214
215215 /**
216216 * The log settings for detailed build logging.
217217 *
218- * @default - None
218+ * @default None
219219 */
220220 readonly logging ?: InfrastructureConfigurationLogging ;
221221
222222 /**
223223 * The availability zone to place Image Builder build and test EC2 instances.
224224 *
225- * @default - EC2 will select a random zone
225+ * @default EC2 will select a random zone
226226 */
227227 readonly ec2InstanceAvailabilityZone ?: string ;
228228
229229 /**
230230 * The ID of the Dedicated Host on which build and test instances run. This only applies if the instance tenancy is
231231 * `host`. This cannot be used with the `ec2InstanceHostResourceGroupArn` parameter.
232232 *
233- * @default - None
233+ * @default None
234234 */
235235 readonly ec2InstanceHostId ?: string ;
236236
237237 /**
238238 * The ARN of the host resource group on which build and test instances run. This only applies if the instance tenancy
239239 * is `host`. This cannot be used with the `ec2InstanceHostId` parameter.
240240 *
241- * @default - None
241+ * @default None
242242 */
243243 readonly ec2InstanceHostResourceGroupArn ?: string ;
244244
245245 /**
246246 * The tenancy of the instance. Dedicated tenancy runs instances on single-tenant hardware, while host tenancy runs
247247 * instances on a dedicated host. Shared tenancy is used by default.
248248 *
249- * @default - Tenancy.DEFAULT
249+ * @default Tenancy.DEFAULT
250250 */
251251 readonly ec2InstanceTenancy ?: Tenancy ;
252252
253253 /**
254254 * The additional tags to assign to the Amazon EC2 instance that Image Builder launches during the build process.
255255 *
256- * @default - None
256+ * @default None
257257 */
258258 readonly resourceTags ?: { [ key : string ] : string } ;
259259
260260 /**
261261 * The tags to apply to the infrastructure configuration
262262 *
263- * @default - None
263+ * @default None
264264 */
265265 readonly tags ?: { [ key : string ] : string } ;
266266}
@@ -389,7 +389,7 @@ export class InfrastructureConfiguration extends InfrastructureConfigurationBase
389389 public readonly instanceProfile : iam . IInstanceProfile ;
390390
391391 /**
392- * The role associateded with the EC2 instance profile used for the build
392+ * The role associated with the EC2 instance profile used for the build
393393 */
394394 public readonly role ?: iam . IRole ;
395395
@@ -463,6 +463,14 @@ export class InfrastructureConfiguration extends InfrastructureConfigurationBase
463463 ) ;
464464 }
465465
466+ if ( props . httpPutResponseHopLimit !== undefined && props . httpPutResponseHopLimit < 1 ) {
467+ throw new cdk . ValidationError ( 'httpPutResponseHopLimit must be at least 1' , this ) ;
468+ }
469+
470+ if ( props . httpPutResponseHopLimit !== undefined && props . httpPutResponseHopLimit > 64 ) {
471+ throw new cdk . ValidationError ( 'httpPutResponseHopLimit must be at most 64' , this ) ;
472+ }
473+
466474 if ( ! props . instanceProfile && ! props . role ) {
467475 this . autoGeneratedInstanceProfileRole = new iam . Role ( this , 'InstanceProfileRole' , {
468476 assumedBy : new iam . ServicePrincipal ( 'ec2.amazonaws.com' ) ,
@@ -481,16 +489,27 @@ export class InfrastructureConfiguration extends InfrastructureConfigurationBase
481489 this . role = this . instanceProfile . role ;
482490 this . logBucket = props . logging ?. s3Bucket ;
483491
484- if ( this . logBucket && this . role && props . logging ?. s3KeyPrefix !== undefined ) {
485- this . logBucket . grantPut ( this . role , `${ props . logging . s3KeyPrefix } /*` ) ;
492+ if ( this . logBucket && this . role ) {
493+ this . logBucket . grantPut ( this . role , props . logging ?. s3KeyPrefix ? `${ props . logging . s3KeyPrefix } /*` : '*' ) ;
486494 }
487495
488- const placement : CfnInfrastructureConfiguration . PlacementProperty = {
489- ...( props . ec2InstanceAvailabilityZone && { availabilityZone : props . ec2InstanceAvailabilityZone } ) ,
490- ...( props . ec2InstanceHostId && { hostId : props . ec2InstanceHostId } ) ,
491- ...( props . ec2InstanceHostResourceGroupArn && { hostResourceGroupArn : props . ec2InstanceHostResourceGroupArn } ) ,
492- ...( props . ec2InstanceTenancy && { tenancy : props . ec2InstanceTenancy } ) ,
493- } ;
496+ const hasPlacementOptions =
497+ props . ec2InstanceAvailabilityZone !== undefined ||
498+ props . ec2InstanceHostId !== undefined ||
499+ props . ec2InstanceHostResourceGroupArn !== undefined ||
500+ props . ec2InstanceTenancy !== undefined ;
501+ const placement : CfnInfrastructureConfiguration . PlacementProperty | undefined = hasPlacementOptions
502+ ? {
503+ ...( props . ec2InstanceAvailabilityZone !== undefined && {
504+ availabilityZone : props . ec2InstanceAvailabilityZone ,
505+ } ) ,
506+ ...( props . ec2InstanceHostId !== undefined && { hostId : props . ec2InstanceHostId } ) ,
507+ ...( props . ec2InstanceHostResourceGroupArn !== undefined && {
508+ hostResourceGroupArn : props . ec2InstanceHostResourceGroupArn ,
509+ } ) ,
510+ ...( props . ec2InstanceTenancy !== undefined && { tenancy : props . ec2InstanceTenancy } ) ,
511+ }
512+ : undefined ;
494513
495514 const infrastructureConfiguration = new CfnInfrastructureConfiguration ( this , 'Resource' , {
496515 name : this . physicalName ,
@@ -512,7 +531,7 @@ export class InfrastructureConfiguration extends InfrastructureConfigurationBase
512531 } ,
513532 } ,
514533 } ) ,
515- placement : Object . keys ( placement ) . length ? placement : undefined ,
534+ ... ( placement && { placement } ) ,
516535 resourceTags : props . resourceTags ,
517536 securityGroupIds : props . securityGroups ?. length
518537 ? props . securityGroups ?. map ( ( securityGroup ) => securityGroup . securityGroupId )
0 commit comments