Skip to content

Commit 46352d2

Browse files
authored
Merge pull request #14182 from aws-amplify/gen2-migrations-execute
Initialize non-custom category generator without custom predicate
2 parents 7b2b987 + 7de7495 commit 46352d2

5 files changed

Lines changed: 85 additions & 25 deletions

File tree

packages/amplify-migration-template-gen/src/resolvers/cfn-output-resolver.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,28 @@ describe('CFNOutputResolver', () => {
199199
TopicName: 'snsTopic',
200200
},
201201
},
202+
CustomS3AutoDeleteObjectsCustomResourceProviderHandler: {
203+
Type: 'AWS::Lambda::Function',
204+
Properties: {
205+
FunctionName: 'CustomS3AutoDeleteObjectsCustomResourceProviderHandler',
206+
Handler: 'index.handler',
207+
Code: {
208+
ZipFile: 'exports.handler = function() {}',
209+
},
210+
Runtime: 'nodejs14.x',
211+
},
212+
},
213+
CustomS3AutoDeleteObjects: {
214+
Type: 'Custom::S3AutoDeleteObjects',
215+
Properties: {
216+
ServiceToken: {
217+
'Fn::GetAtt': ['CustomS3AutoDeleteObjectsCustomResourceProviderHandler', 'Arn'],
218+
},
219+
BucketName: {
220+
Ref: 'MyS3Bucket',
221+
},
222+
},
223+
},
202224
},
203225
};
204226
const expectedTemplate: CFNTemplate = {
@@ -372,8 +394,27 @@ describe('CFNOutputResolver', () => {
372394
TopicName: 'snsTopic',
373395
},
374396
},
397+
CustomS3AutoDeleteObjectsCustomResourceProviderHandler: {
398+
Type: 'AWS::Lambda::Function',
399+
Properties: {
400+
FunctionName: 'CustomS3AutoDeleteObjectsCustomResourceProviderHandler',
401+
Handler: 'index.handler',
402+
Code: {
403+
ZipFile: 'exports.handler = function() {}',
404+
},
405+
Runtime: 'nodejs14.x',
406+
},
407+
},
408+
CustomS3AutoDeleteObjects: {
409+
Type: 'Custom::S3AutoDeleteObjects',
410+
Properties: {
411+
ServiceToken: 'arn:aws:lambda:us-east-1:12345:function:mycustomS3AutoDeleteObjectsLambdaFunction',
412+
BucketName: 'test-bucket',
413+
},
414+
},
375415
},
376416
};
417+
377418
it('should resolve output references', () => {
378419
expect(
379420
new CfnOutputResolver(template, 'us-east-1', '12345').resolve(
@@ -431,6 +472,15 @@ describe('CFNOutputResolver', () => {
431472
Timestamp: new Date('2025-04-02T22:27:41.603000+00:00'),
432473
ResourceStatus: 'CREATE_COMPLETE',
433474
},
475+
{
476+
StackName: 'amplify-amplifycodegen-dev',
477+
StackId: 'arn:aws:cloudformation:us-west-2:123456789:stack/amplify-amplifycodegen-dev',
478+
LogicalResourceId: 'CustomS3AutoDeleteObjectsCustomResourceProviderHandler',
479+
PhysicalResourceId: 'mycustomS3AutoDeleteObjectsLambdaFunction',
480+
ResourceType: 'AWS::Lambda::Function',
481+
Timestamp: new Date('2025-04-02T22:27:41.603000+00:00'),
482+
ResourceStatus: 'CREATE_COMPLETE',
483+
},
434484
],
435485
),
436486
).toEqual(expectedTemplate);

packages/amplify-migration-template-gen/src/resolvers/cfn-output-resolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ class CfnOutputResolver {
157157
return {
158158
Arn: `arn:aws:sqs:${this.region}:${this.accountId}:${resourceIdentifier}`,
159159
};
160+
case 'AWS::Lambda::Function':
161+
return {
162+
Arn: `arn:aws:lambda:${this.region}:${this.accountId}:function:${resourceIdentifier}`,
163+
};
160164
default:
161165
return undefined;
162166
}

packages/amplify-migration-template-gen/src/template-generator.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ describe('TemplateGenerator', () => {
834834
CFN_AUTH_TYPE.IdentityPoolRoleAttachment,
835835
CFN_AUTH_TYPE.UserPoolDomain,
836836
],
837-
expect.any(Function),
837+
undefined,
838838
);
839839
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
840840
2,
@@ -848,7 +848,7 @@ describe('TemplateGenerator', () => {
848848
APP_ID,
849849
ENV_NAME,
850850
[CFN_AUTH_TYPE.UserPoolGroup],
851-
expect.any(Function),
851+
undefined,
852852
);
853853
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
854854
3,
@@ -862,7 +862,7 @@ describe('TemplateGenerator', () => {
862862
APP_ID,
863863
ENV_NAME,
864864
[CFN_S3_TYPE.Bucket],
865-
expect.any(Function),
865+
undefined,
866866
);
867867
}
868868

@@ -892,7 +892,7 @@ describe('TemplateGenerator', () => {
892892
CFN_AUTH_TYPE.IdentityPoolRoleAttachment,
893893
CFN_AUTH_TYPE.UserPoolDomain,
894894
],
895-
expect.any(Function),
895+
undefined,
896896
);
897897
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
898898
2,
@@ -906,7 +906,7 @@ describe('TemplateGenerator', () => {
906906
APP_ID,
907907
ENV_NAME,
908908
[CFN_AUTH_TYPE.UserPoolGroup],
909-
expect.any(Function),
909+
undefined,
910910
);
911911
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
912912
3,
@@ -920,7 +920,7 @@ describe('TemplateGenerator', () => {
920920
APP_ID,
921921
ENV_NAME,
922922
[CFN_S3_TYPE.Bucket],
923-
expect.any(Function),
923+
undefined,
924924
);
925925
}
926926

@@ -950,7 +950,7 @@ describe('TemplateGenerator', () => {
950950
CFN_AUTH_TYPE.IdentityPoolRoleAttachment,
951951
CFN_AUTH_TYPE.UserPoolDomain,
952952
],
953-
expect.any(Function),
953+
undefined,
954954
);
955955
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
956956
2,
@@ -964,7 +964,7 @@ describe('TemplateGenerator', () => {
964964
APP_ID,
965965
ENV_NAME,
966966
[CFN_AUTH_TYPE.UserPoolGroup],
967-
expect.any(Function),
967+
undefined,
968968
);
969969
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
970970
3,
@@ -978,8 +978,9 @@ describe('TemplateGenerator', () => {
978978
APP_ID,
979979
ENV_NAME,
980980
[CFN_S3_TYPE.Bucket],
981-
expect.any(Function),
981+
undefined,
982982
);
983+
// custom resource category
983984
expect(CategoryTemplateGenerator).toHaveBeenNthCalledWith(
984985
4,
985986
GEN1_ROOT_STACK_NAME,

packages/amplify-migration-template-gen/src/template-generator.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,12 @@ class TemplateGenerator {
260260
let updatingGen1CategoryStack;
261261
try {
262262
const { newTemplate, parameters: gen1StackParameters } = await categoryTemplateGenerator.generateGen1PreProcessTemplate();
263-
264263
assert(gen1StackParameters);
265264
updatingGen1CategoryStack = ora(`Updating Gen 1 ${this.getStackCategoryName(category)} stack...`).start();
266265

267266
const gen1StackUpdateStatus = await tryUpdateStack(this.cfnClient, sourceCategoryStackId, gen1StackParameters, newTemplate);
268267

269-
assert(gen1StackUpdateStatus === CFNStackStatus.UPDATE_COMPLETE);
268+
assert(gen1StackUpdateStatus === CFNStackStatus.UPDATE_COMPLETE, `Gen 1 stack is in an invalid state: ${gen1StackUpdateStatus}`);
270269
updatingGen1CategoryStack.succeed(`Updated Gen 1 ${this.getStackCategoryName(category)} stack successfully`);
271270

272271
return newTemplate;
@@ -297,7 +296,7 @@ class TemplateGenerator {
297296

298297
const gen2StackUpdateStatus = await tryUpdateStack(this.cfnClient, destinationCategoryStackId, parameters ?? [], newTemplate);
299298

300-
assert(gen2StackUpdateStatus === CFNStackStatus.UPDATE_COMPLETE);
299+
assert(gen2StackUpdateStatus === CFNStackStatus.UPDATE_COMPLETE, `Gen 2 stack is in an invalid state: ${gen2StackUpdateStatus}`);
301300
updatingGen2CategoryStack.succeed(`Updated Gen 2 ${this.getStackCategoryName(category)} stack successfully`);
302301

303302
return { newTemplate, oldTemplate, parameters };
@@ -325,7 +324,7 @@ class TemplateGenerator {
325324
destinationStackId,
326325
this.createCategoryTemplateGenerator(sourceStackId, destinationStackId, config.resourcesToRefactor),
327326
]);
328-
} else if (customResourceMap && !Object.values(NON_CUSTOM_RESOURCE_CATEGORY).includes(category as NON_CUSTOM_RESOURCE_CATEGORY)) {
327+
} else if (customResourceMap && this.isCustomResource(category)) {
329328
this.categoryTemplateGenerators.push([
330329
category,
331330
sourceStackId,
@@ -354,17 +353,19 @@ class TemplateGenerator {
354353
this.appId,
355354
this.environmentName,
356355
resourcesToRefactor,
357-
(_resourcesToMove: CFN_CATEGORY_TYPE[], cfnResource: [string, CFNResource]) => {
358-
const [logicalId] = cfnResource;
359-
360-
// Check if customResourceMap contains the logical ID
361-
return (
362-
customResourceMap?.some(
363-
(resourceMapping) =>
364-
resourceMapping.Source.LogicalResourceId === logicalId || resourceMapping.Destination.LogicalResourceId === logicalId,
365-
) ?? false
366-
);
367-
},
356+
customResourceMap
357+
? (_resourcesToMove: CFN_CATEGORY_TYPE[], cfnResource: [string, CFNResource]) => {
358+
const [logicalId] = cfnResource;
359+
360+
// Check if customResourceMap contains the logical ID
361+
return (
362+
customResourceMap?.some(
363+
(resourceMapping) =>
364+
resourceMapping.Source.LogicalResourceId === logicalId || resourceMapping.Destination.LogicalResourceId === logicalId,
365+
) ?? false
366+
);
367+
}
368+
: undefined,
368369
);
369370
}
370371

packages/amplify-migration-template-gen/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export enum CFN_SQS_TYPE {
109109
Queue = 'AWS::SQS::Queue',
110110
}
111111

112-
export type CFN_RESOURCE_TYPES = CFN_AUTH_TYPE | CFN_S3_TYPE | CFN_IAM_TYPE | CFN_SQS_TYPE;
112+
export enum CFN_LAMBDA_TYPE {
113+
Function = 'AWS::Lambda::Function',
114+
}
115+
116+
export type CFN_RESOURCE_TYPES = CFN_AUTH_TYPE | CFN_S3_TYPE | CFN_IAM_TYPE | CFN_SQS_TYPE | CFN_LAMBDA_TYPE;
113117

114118
export type AWS_RESOURCE_ATTRIBUTES = 'Arn';
115119

0 commit comments

Comments
 (0)