Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8ad8d1f
feat(cli-internal): add migration support for overriding default reso…
dgandhi62 Apr 8, 2026
3c9cef2
feat: added six unit tests
dgandhi62 Apr 8, 2026
f5e65a1
feat: update pre-generate snapshot
dgandhi62 Apr 8, 2026
e292307
feat: post generate snapshot
dgandhi62 Apr 9, 2026
15fc409
feat: pre-refactor snapshot
dgandhi62 Apr 9, 2026
756f15d
feat(cli-internal): use cdk assets for vtl resolver overrides
dgandhi62 Apr 9, 2026
5e4f841
feat: update pre-refactor snapshots
dgandhi62 Apr 9, 2026
9285618
chore: update README
dgandhi62 Apr 9, 2026
6597d55
feat: update post refactor
dgandhi62 Apr 9, 2026
a2fd1e4
chore: sanitized snapshots
dgandhi62 Apr 9, 2026
d63cf05
chore: sanitize apikey
dgandhi62 Apr 10, 2026
0af163c
feat: add frontend tests
dgandhi62 Apr 10, 2026
9d8e7fa
feat: update frontend test
dgandhi62 Apr 10, 2026
459dcbe
chore: reset snapshots
dgandhi62 Apr 20, 2026
d9d8e53
chore: mid work
dgandhi62 Apr 21, 2026
a1d3094
chore: update tests
dgandhi62 Apr 21, 2026
6bb6a61
feat: updated moodboard snapshots
dgandhi62 Apr 21, 2026
94a0d08
chore: reset apps
dgandhi62 Apr 21, 2026
d0479f4
chore: reset amplify-migration-apps to upstream/gen2-migration
dgandhi62 Apr 21, 2026
9939f8c
feat: update pre-generate snapshot
dgandhi62 Apr 21, 2026
d137571
feat(cli-internal): add migration support for overriding default reso…
dgandhi62 Apr 22, 2026
4ce5d55
chore: mid work
dgandhi62 Apr 22, 2026
b11c053
feat: update snapshots
dgandhi62 Apr 22, 2026
fc6726e
feat: update tests
dgandhi62 Apr 22, 2026
95998f9
fix: fix algorithm
dgandhi62 Apr 22, 2026
18139ee
chore: update snapshots
dgandhi62 Apr 22, 2026
62fe0b4
chore: fix tests
dgandhi62 Apr 22, 2026
3024ffb
Merge branch 'gen2-migration' of https://github.com/aws-amplify/ampli…
dgandhi62 Apr 23, 2026
2fe0d34
feat: update code
dgandhi62 Apr 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@ amplify-migration-apps/**/_snapshot.*.actual*
.pr-body.ai-generated.md
.commit-message.ai-generated.txt
.kiro-session.ai-generated.md
.kiro/specs/
**/.gen2-migration/refactor.operations
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { storage } from './storage/resource';
import { moodboardGetRandomEmoji } from './function/moodboardGetRandomEmoji/resource';
import { moodboardKinesisReader } from './function/moodboardKinesisReader/resource';
import { moodboardKinesisTrigger } from './function/moodboardKinesisTrigger/resource';
import { CfnResolver } from 'aws-cdk-lib/aws-appsync';
import { KinesisEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
import { StartingPosition } from 'aws-cdk-lib/aws-lambda';
import { Stream } from 'aws-cdk-lib/aws-kinesis';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { readdirSync } from 'fs';
import { defineBackend } from '@aws-amplify/backend';
import { defineAnalytics } from './analytics/resource';
import { Duration, aws_iam } from 'aws-cdk-lib';
import { Duration, aws_appsync, aws_iam } from 'aws-cdk-lib';
import * as assets from 'aws-cdk-lib/aws-s3-assets';
// import { Tags } from 'aws-cdk-lib';

const backend = defineBackend({
Expand Down Expand Up @@ -52,6 +57,86 @@ cfnGraphqlApi.additionalAuthenticationProviders = [
},
},
];
const __dirname = dirname(fileURLToPath(import.meta.url));
const resolversDir = join(__dirname, 'data/resolvers');
const resolverFiles = readdirSync(resolversDir).filter(
(f) =>
(f.endsWith('.req.vtl') || f.endsWith('.res.vtl')) &&
f.split('.').length === 4
);
for (const file of resolverFiles) {
const parts = file.replace('.req.vtl', '').replace('.res.vtl', '').split('.');
const [typeName, fieldName] = parts;
const isRequest = file.endsWith('.req.vtl');
const functionId = `${typeName}${
fieldName.charAt(0).toUpperCase() + fieldName.slice(1)
}DataResolverFn`;
const pipelineFunction =
backend.data.resources.cfnResources.cfnFunctionConfigurations[functionId];
if (pipelineFunction) {
const templatePath = join(resolversDir, file);
const vtlTemplate = new assets.Asset(backend.data, `VTLTemplate-${file}`, {
path: templatePath,
});
if (isRequest) {
pipelineFunction.requestMappingTemplateS3Location =
vtlTemplate.s3ObjectUrl;
} else {
pipelineFunction.responseMappingTemplateS3Location =
vtlTemplate.s3ObjectUrl;
}
}
}
const noneDataSource =
backend.data.resources.graphqlApi.addNoneDataSource('none');
const MutationcreateBoardinit2 = new aws_appsync.AppsyncFunction(
backend.data.stack,
'MutationcreateBoardinit2',
{
name: 'MutationcreateBoardinit2',
api: backend.data.resources.graphqlApi,
dataSource: noneDataSource,
requestMappingTemplate: aws_appsync.MappingTemplate.fromFile(
join(resolversDir, 'Mutation.createBoard.init.2.req.vtl')
),
responseMappingTemplate: aws_appsync.MappingTemplate.fromString(
'$util.toJson($ctx.prev.result)'
),
}
);
const MutationcreateBoardfinish1 = new aws_appsync.AppsyncFunction(
backend.data.stack,
'MutationcreateBoardfinish1',
{
name: 'MutationcreateBoardfinish1',
api: backend.data.resources.graphqlApi,
dataSource: noneDataSource,
requestMappingTemplate:
aws_appsync.MappingTemplate.fromString('$util.toJson({})'),
responseMappingTemplate: aws_appsync.MappingTemplate.fromFile(
join(resolversDir, 'Mutation.createBoard.finish.1.res.vtl')
),
}
);
const mutationCreateBoardResolver = backend.data.resources.cfnResources
.cfnResolvers['Mutation.createBoard'] as CfnResolver;
const mutationCreateBoardPipelineFunctions =
(
mutationCreateBoardResolver.pipelineConfig as CfnResolver.PipelineConfigProperty
).functions || [];
mutationCreateBoardPipelineFunctions.splice(
1,
0,
MutationcreateBoardinit2.functionId
);
mutationCreateBoardPipelineFunctions.splice(
5,
0,
MutationcreateBoardfinish1.functionId
);
mutationCreateBoardResolver.pipelineConfig = {
functions: mutationCreateBoardPipelineFunctions,
};
const s3Bucket = backend.storage.resources.cfnResources.cfnBucket;
// Use this bucket name post refactor
// s3Bucket.bucketName = 'moodboard20e29595008142e3ad16f01c4066e1c4x-x';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## [Start] Custom finish slot - Append "(new!)" tag to board name in response. **
## This runs as the final step before the response is returned to the client.
## It adds a visual indicator that the board was just created.

#if( $ctx.error )
$util.error($ctx.error.message, $ctx.error.type)
#end

#if( !$util.isNullOrEmpty($ctx.prev.result) )
#set( $result = $ctx.prev.result )
#if( !$util.isNullOrEmpty($result.name) )
$util.qr($result.put("name", "${result.name} (new!)"))
#end
$util.toJson($result)
#else
$util.toJson($ctx.prev.result)
#end
## [End] Custom finish slot - Append "(new!)" tag to board name in response. **
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## [Start] Custom init slot - Auto-prefix board name with time-of-day emoji. **
## This runs after init.1 (which sets id, createdAt, updatedAt).
## We read the hour from createdAt and prepend a matching emoji to the board name.

#set( $createdAt = $ctx.stash.defaultValues.createdAt )
#set( $hour = $util.parseInt($util.time.parseISO8601ToEpochMilliSeconds($createdAt)) )
## Convert epoch millis to approximate hour (UTC)
#set( $hourOfDay = $hour / 3600000 % 24 )

#if( $hourOfDay >= 5 && $hourOfDay < 12 )
#set( $emoji = "🌅" )
#elseif( $hourOfDay >= 12 && $hourOfDay < 18 )
#set( $emoji = "☀️" )
#else
#set( $emoji = "🌙" )
#end

## Prepend the emoji to the board name
#set( $inputName = $util.defaultIfNull($ctx.args.input.name, "") )
$util.qr($ctx.stash.defaultValues.put("name", "${emoji} ${inputName}"))

$util.toJson({
"version": "2018-05-29",
"payload": {}
})
## [End] Custom init slot - Auto-prefix board name with time-of-day emoji. **
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## [Start] Custom List Request - Override to cap results at 50. **
#set( $args = $util.defaultIfNull($ctx.stash.transformedArgs, $ctx.args) )
#set( $limit = $util.defaultIfNull($args.limit, 50) )
## Cap the limit at 50 to keep the board list manageable
#if( $limit > 50 )
#set( $limit = 50 )
#end
#set( $ListRequest = {
"version": "2018-05-29",
"limit": $limit
} )
#if( $args.nextToken )
#set( $ListRequest.nextToken = $args.nextToken )
#end
#if( !$util.isNullOrEmpty($ctx.stash.authFilter) )
#set( $filter = $ctx.stash.authFilter )
#if( !$util.isNullOrEmpty($args.filter) )
#set( $filter = {
"and": [$filter, $args.filter]
} )
#end
#else
#if( !$util.isNullOrEmpty($args.filter) )
#set( $filter = $args.filter )
#end
#end
#if( !$util.isNullOrEmpty($filter) )
#set( $filterExpression = $util.parseJson($util.transform.toDynamoDBFilterExpression($filter)) )
#if( $util.isNullOrEmpty($filterExpression) )
$util.error("Unable to process the filter expression", "Unrecognized Filter")
#end
#if( !$util.isNullOrBlank($filterExpression.expression) )
#if( $filterExpression.expressionValues.size() == 0 )
$util.qr($filterExpression.remove("expressionValues"))
#end
#set( $ListRequest.filter = $filterExpression )
#end
#end
#if( !$util.isNull($ctx.stash.modelQueryExpression) && !$util.isNullOrEmpty($ctx.stash.modelQueryExpression.expression) )
$util.qr($ListRequest.put("operation", "Query"))
$util.qr($ListRequest.put("query", $ctx.stash.modelQueryExpression))
#if( !$util.isNull($args.sortDirection) && $args.sortDirection == "DESC" )
#set( $ListRequest.scanIndexForward = false )
#else
#set( $ListRequest.scanIndexForward = true )
#end
#else
$util.qr($ListRequest.put("operation", "Scan"))
#end
#if( !$util.isNull($ctx.stash.metadata.index) )
#set( $ListRequest.IndexName = $ctx.stash.metadata.index )
#end
$util.toJson($ListRequest)
## [End] Custom List Request. **
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## [Start] Custom ResponseTemplate - Prepend emoji to board names to prove override is active. **
#if( $ctx.error )
$util.error($ctx.error.message, $ctx.error.type)
#end

## Add a pin emoji prefix to each board name so it's visible on the frontend
#foreach( $item in $ctx.result.items )
#if( !$item.name.startsWith("📌 ") )
$util.qr($item.put("name", "📌 $item.name"))
#end
#end

$util.toJson($ctx.result)
## [End] Custom ResponseTemplate. **
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export const data = defineData({
//The "branchname" variable needs to be the same as your deployment branch if you want to reuse your Gen1 app tables
branchName: 'x',
modelNameToTableNameMapping: {
MoodItem: 'MoodItem-g26hrobfy5b5pniveska5ylg4u-x',
Board: 'Board-g26hrobfy5b5pniveska5ylg4u-x',
KinesisEventCount: 'KinesisEventCount-g26hrobfy5b5pniveska5ylg4u-x',
MoodItem: 'MoodItem-xn3j437hmbcnfl2xxwcnmqujpy-x',
Board: 'Board-xn3j437hmbcnfl2xxwcnmqujpy-x',
KinesisEventCount: 'KinesisEventCount-xn3j437hmbcnfl2xxwcnmqujpy-x',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"PolicyName": "moodboardKinesis-auth-policy-gen2-x",
"Roles": [
"amplify-moodboard26041519-amplifyAuthauthenticatedU-hG08sRlsZcsb"
"amplify-moodboard26042215-amplifyAuthauthenticatedU-kysyAl3WUL5W"
]
},
"UpdateReplacePolicy": "Delete",
Expand All @@ -46,7 +46,7 @@
},
"PolicyName": "moodboardKinesis-unauth-policy-gen2-x",
"Roles": [
"amplify-moodboard26041519-amplifyAuthunauthenticate-Six3YvIOxgGy"
"amplify-moodboard26042215-amplifyAuthunauthenticate-6uKlXRpRthU1"
]
},
"UpdateReplacePolicy": "Delete",
Expand All @@ -58,7 +58,7 @@
"CDKMetadata": {
"Type": "AWS::CDK::Metadata",
"Properties": {
"Analytics": "v2:deflate64:H4sIAAAAAAAA/yXHUQqDMAwA0LP432ZdwBP4v415AKlthFhbh0knQ7z7GPt6PARsHbjG72JDTHbhEY4biVLs1Ydk/C7DkbiQsEA3lV438tmwz7891oXD5zTdVO5VX1VPU9ZIMMvljQh4BdfMwmy3WpQzwfPvF8PdMhZ3AAAA"
"Analytics": "v2:deflate64:H4sIAAAAAAAA/yXHUQ6CMAwA0LPwv9W5yAn4VyMHIHUrSRkbhnYSQ7i7MX69PA++deAa3MSGmOzMT9ivJEqxVwzJ4CbDnriQsEA3ll5XwmwY82/3ZebwOUw3llvVV9XDlCUSTHJ6+wucW3DNJMx2rUU5Ezz+fgEIqID2dwAAAA=="
},
"Metadata": {
"aws:cdk:path": "amplify-moodboard-e2e-sandbox-x/analytics/CDKMetadata/Default"
Expand All @@ -76,7 +76,7 @@
"kinesisStreamShardCount": {
"Value": "1"
},
"amplifymoodboarde2esandbox685dc54d14analyticsmoodboardKinesisKinesisStream0B86977BArn": {
"amplifymoodboarde2esandbox4f6bc84565analyticsmoodboardKinesisKinesisStreamE12E9220Arn": {
"Value": "arn:aws:kinesis:us-east-1:123456789012:stream/moodboardKinesis-gen2-x"
}
},
Expand Down Expand Up @@ -347,10 +347,10 @@
}
},
"Parameters": {
"referencetoamplifymoodboarde2esandbox685dc54d14authNestedStackauthNestedStackResourceAFCFFB8EOutputsamplifymoodboarde2esandbox685dc54d14authamplifyAuthauthenticatedUserRoleECA75B03Ref": {
"referencetoamplifymoodboarde2esandbox4f6bc84565authNestedStackauthNestedStackResource564C9872Outputsamplifymoodboarde2esandbox4f6bc84565authamplifyAuthauthenticatedUserRole9FBEFADDRef": {
"Type": "String"
},
"referencetoamplifymoodboarde2esandbox685dc54d14authNestedStackauthNestedStackResourceAFCFFB8EOutputsamplifymoodboarde2esandbox685dc54d14authamplifyAuthunauthenticatedUserRole92D42D98Ref": {
"referencetoamplifymoodboarde2esandbox4f6bc84565authNestedStackauthNestedStackResource564C9872Outputsamplifymoodboarde2esandbox4f6bc84565authamplifyAuthunauthenticatedUserRole2ADAA45CRef": {
"Type": "String"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "us-east-1:3a5eeecb-0ea0-4cbe-93f4-2094213caf65"
"cognito-identity.amazonaws.com:aud": "us-east-1:fd95d154-e9d4-426b-b587-e4c8b3c72426"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "authenticated"
Expand Down Expand Up @@ -54,7 +54,7 @@
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "us-east-1:3a5eeecb-0ea0-4cbe-93f4-2094213caf65"
"cognito-identity.amazonaws.com:aud": "us-east-1:fd95d154-e9d4-426b-b587-e4c8b3c72426"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "unauthenticated"
Expand Down Expand Up @@ -92,7 +92,7 @@
"CDKMetadata": {
"Type": "AWS::CDK::Metadata",
"Properties": {
"Analytics": "v2:deflate64:H4sIAAAAAAAA/02LwQrCMBBEv6X3dK0BP0B68iLS4llisuq26Qaa1SIh/y5Fqj3NzJsZDXpXQVWYKZbW9aWnK6QjRkHXirG9MlO8JBvuTBIgnSOOpxC8qm/884upPSHLuvqTg0MWkvdyXucmeNyLGPsYkCUrMgOkGc7DWXPOioND6OLmpTXoLVRFF4nK8clCA0Lz1Q/RUZAezgAAAA=="
"Analytics": "v2:deflate64:H4sIAAAAAAAA/02LwQ6CMBBEv4V7WZHIBxhOXoyBeDa1XXWhbBO6SkzTfzfEoJxm5s1MCWVVQJHpKeTG9rmjK8QjBkHbija90lO4ROPvTOIhngOOJ++dqm/884upHSHLuvqTg0UWkvdyXufGO9yLaPMYkCUp0gPEGc7DWVNKir1F6MLmVe5gW0GRdYEoH58sNCA0X/0AGiQi/s4AAAA="
},
"Metadata": {
"aws:cdk:path": "amplify-moodboard-e2e-sandbox-x/auth/CDKMetadata/Default"
Expand Down Expand Up @@ -367,20 +367,20 @@
}
},
"Outputs": {
"amplifymoodboarde2esandbox685dc54d14authamplifyAuthUserPool390B0381Ref": {
"Value": "us-east-1_5iU0nP22B"
"amplifymoodboarde2esandbox4f6bc84565authamplifyAuthUserPool88309446Ref": {
"Value": "us-east-1_S5zs48BQ8"
},
"amplifymoodboarde2esandbox685dc54d14authamplifyAuthUserPoolAppClient54FF5C73Ref": {
"Value": "6dkse6kuhg779dhl6glmefrmrq"
"amplifymoodboarde2esandbox4f6bc84565authamplifyAuthUserPoolAppClient9141812BRef": {
"Value": "q6pv2fdcs4s7to7ocp8th73n4"
},
"amplifymoodboarde2esandbox685dc54d14authamplifyAuthIdentityPoolA541B351Ref": {
"Value": "us-east-1:3a5eeecb-0ea0-4cbe-93f4-2094213caf65"
"amplifymoodboarde2esandbox4f6bc84565authamplifyAuthIdentityPoolB9F41888Ref": {
"Value": "us-east-1:fd95d154-e9d4-426b-b587-e4c8b3c72426"
},
"amplifymoodboarde2esandbox685dc54d14authamplifyAuthauthenticatedUserRoleECA75B03Ref": {
"Value": "amplify-moodboard26041519-amplifyAuthauthenticatedU-hG08sRlsZcsb"
"amplifymoodboarde2esandbox4f6bc84565authamplifyAuthauthenticatedUserRole9FBEFADDRef": {
"Value": "amplify-moodboard26042215-amplifyAuthauthenticatedU-kysyAl3WUL5W"
},
"amplifymoodboarde2esandbox685dc54d14authamplifyAuthunauthenticatedUserRole92D42D98Ref": {
"Value": "amplify-moodboard26041519-amplifyAuthunauthenticate-Six3YvIOxgGy"
"amplifymoodboarde2esandbox4f6bc84565authamplifyAuthunauthenticatedUserRole2ADAA45CRef": {
"Value": "amplify-moodboard26042215-amplifyAuthunauthenticate-6uKlXRpRthU1"
}
}
}
Loading
Loading