@@ -4,20 +4,22 @@ import type {
4
4
} from '@aws-lambda-powertools/testing-utils/types' ;
5
5
import {
6
6
concatenateResourceName ,
7
- getRuntimeKey ,
8
7
getArchitectureKey ,
8
+ getRuntimeKey ,
9
9
type TestStack ,
10
10
} from '@aws-lambda-powertools/testing-utils' ;
11
11
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda' ;
12
12
import { TestDynamodbTable } from '@aws-lambda-powertools/testing-utils/resources/dynamodb' ;
13
13
import { marshall } from '@aws-sdk/util-dynamodb' ;
14
- import { CfnOutput , Stack } from 'aws-cdk-lib' ;
14
+ import { CfnOutput , Duration , RemovalPolicy , Stack } from 'aws-cdk-lib' ;
15
15
import {
16
- CfnApplication ,
17
- CfnConfigurationProfile ,
18
- CfnDeployment ,
19
- CfnDeploymentStrategy ,
20
- CfnEnvironment ,
16
+ Application ,
17
+ ConfigurationContent ,
18
+ ConfigurationType ,
19
+ DeploymentStrategy ,
20
+ HostedConfiguration ,
21
+ IEnvironment ,
22
+ RolloutStrategy ,
21
23
CfnHostedConfigurationVersion ,
22
24
} from 'aws-cdk-lib/aws-appconfig' ;
23
25
import { Effect , PolicyStatement } from 'aws-cdk-lib/aws-iam' ;
@@ -212,10 +214,10 @@ class TestDynamodbTableWithItems extends TestDynamodbTable {
212
214
* A set of AppConfig resources that can be used in tests.
213
215
*/
214
216
class TestAppConfigWithProfiles extends Construct {
215
- private readonly application : CfnApplication ;
216
- private readonly deploymentStrategy : CfnDeploymentStrategy ;
217
- private readonly environment : CfnEnvironment ;
218
- private readonly profiles : CfnDeployment [ ] = [ ] ;
217
+ private readonly application : Application ;
218
+ private readonly deploymentStrategy : DeploymentStrategy ;
219
+ private readonly environment : IEnvironment ;
220
+ private readonly profiles : HostedConfiguration [ ] = [ ] ;
219
221
220
222
public constructor (
221
223
testStack : TestStack ,
@@ -240,77 +242,55 @@ class TestAppConfigWithProfiles extends Construct {
240
242
241
243
const { profiles } = props ;
242
244
243
- this . application = new CfnApplication (
244
- testStack . stack ,
245
- `app-${ randomUUID ( ) } ` ,
246
- {
247
- name : randomUUID ( ) ,
248
- }
249
- ) ;
245
+ this . application = new Application ( testStack . stack , `app-${ randomUUID ( ) } ` , {
246
+ applicationName : randomUUID ( ) ,
247
+ description : 'Test application for Powertools Parameters' ,
248
+ } ) ;
250
249
251
- this . deploymentStrategy = new CfnDeploymentStrategy (
252
- testStack . stack ,
253
- `de-${ randomUUID ( ) } ` ,
254
- {
255
- name : randomUUID ( ) ,
256
- deploymentDurationInMinutes : 0 ,
257
- growthFactor : 100 ,
258
- replicateTo : 'NONE' ,
259
- finalBakeTimeInMinutes : 0 ,
260
- }
261
- ) ;
250
+ this . environment = this . application . addEnvironment ( `ce-${ randomUUID ( ) } ` , {
251
+ environmentName : randomUUID ( ) ,
252
+ description : 'Test environment for Powertools Parameters' ,
253
+ } ) ;
262
254
263
- this . environment = new CfnEnvironment (
255
+ this . deploymentStrategy = new DeploymentStrategy (
264
256
testStack . stack ,
265
- `ce -${ randomUUID ( ) } ` ,
257
+ `de -${ randomUUID ( ) } ` ,
266
258
{
267
- name : randomUUID ( ) ,
268
- applicationId : this . application . ref ,
259
+ deploymentStrategyName : randomUUID ( ) ,
260
+ description : 'Test deployment strategy for Powertools Parameter' ,
261
+ rolloutStrategy : RolloutStrategy . linear ( {
262
+ deploymentDuration : Duration . minutes ( 0 ) ,
263
+ growthFactor : 100 ,
264
+ finalBakeTime : Duration . minutes ( 0 ) ,
265
+ } ) ,
269
266
}
270
267
) ;
271
268
272
- profiles . forEach ( ( profile , index ) => {
273
- const configProfile = new CfnConfigurationProfile (
269
+ profiles . forEach ( ( profile ) => {
270
+ const config = new HostedConfiguration (
274
271
testStack . stack ,
275
- `cp -${ randomUUID ( ) } ` ,
272
+ `hc -${ randomUUID ( ) } ` ,
276
273
{
277
- name : randomUUID ( ) ,
278
- applicationId : this . application . ref ,
279
- locationUri : 'hosted' ,
280
- type : profile . type ,
274
+ name : `${ randomUUID ( ) } -${ profile . nameSuffix } ` ,
275
+ description : 'Test hosted configuration for Powertools Parameter' ,
276
+ deploymentStrategy : this . deploymentStrategy ,
277
+ deployTo : [ this . environment ] ,
278
+ application : this . application ,
279
+ type :
280
+ profile . type === 'AWS.Freeform'
281
+ ? ConfigurationType . FREEFORM
282
+ : ConfigurationType . FEATURE_FLAGS ,
283
+ content : ConfigurationContent . fromInlineJson (
284
+ profile . content . content ,
285
+ profile . content . contentType
286
+ ) ,
281
287
}
282
288
) ;
283
-
284
- const configVersion = new CfnHostedConfigurationVersion (
285
- testStack . stack ,
286
- `cv-${ randomUUID ( ) } ` ,
287
- {
288
- applicationId : this . application . ref ,
289
- configurationProfileId : configProfile . ref ,
290
- ...profile . content ,
291
- }
292
- ) ;
293
-
294
- const deployment = new CfnDeployment (
295
- testStack . stack ,
296
- concatenateResourceName ( {
297
- testName : testStack . testName ,
298
- resourceName : profile . nameSuffix ,
299
- } ) ,
300
- {
301
- applicationId : this . application . ref ,
302
- configurationProfileId : configProfile . ref ,
303
- configurationVersion : configVersion . ref ,
304
- deploymentStrategyId : this . deploymentStrategy . ref ,
305
- environmentId : this . environment . ref ,
306
- }
307
- ) ;
308
-
309
- if ( index > 0 && this . profiles ) {
310
- deployment . node . addDependency ( this . profiles [ index - 1 ] ) ;
311
- }
312
-
313
- this . profiles . push ( deployment ) ;
289
+ // The default is RETAIN so this escape hatch is needed to override it
290
+ (
291
+ config . node . defaultChild as CfnHostedConfigurationVersion
292
+ ) . applyRemovalPolicy ( RemovalPolicy . DESTROY ) ;
293
+ this . profiles . push ( config ) ;
314
294
} ) ;
315
295
}
316
296
@@ -320,8 +300,8 @@ class TestAppConfigWithProfiles extends Construct {
320
300
* @param fn The function to add the environment variables to
321
301
*/
322
302
public addEnvVariablesToFunction ( fn : TestNodejsFunction ) : void {
323
- fn . addEnvironment ( 'APPLICATION_NAME' , this . application . name ) ;
324
- fn . addEnvironment ( 'ENVIRONMENT_NAME' , this . environment . name ) ;
303
+ fn . addEnvironment ( 'APPLICATION_NAME' , this . application . name ! ) ;
304
+ fn . addEnvironment ( 'ENVIRONMENT_NAME' , this . environment . name ! ) ;
325
305
fn . addEnvironment (
326
306
'FREEFORM_JSON_NAME' ,
327
307
this . profiles [ 0 ] . configurationProfileId
@@ -349,7 +329,7 @@ class TestAppConfigWithProfiles extends Construct {
349
329
this . profiles . forEach ( ( profile ) => {
350
330
const appConfigConfigurationArn = Stack . of ( fn ) . formatArn ( {
351
331
service : 'appconfig' ,
352
- resource : `application/${ profile . applicationId } /environment/${ profile . environmentId } /configuration/${ profile . configurationProfileId } ` ,
332
+ resource : `application/${ profile . application . applicationId } /environment/${ profile . deployTo ! [ 0 ] . environmentId } /configuration/${ profile . configurationProfileId } ` ,
353
333
} ) ;
354
334
355
335
fn . addToRolePolicy (
0 commit comments