Skip to content

Commit ef60c18

Browse files
committed
chore: mid-work
1 parent 3392aad commit ef60c18

4 files changed

Lines changed: 38 additions & 35 deletions

File tree

amplify-migration-apps/media-vault/_snapshot.post.generate/amplify/backend.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { thumbnailgen } from './storage/thumbnailgen/resource';
55
import { addusertogroup } from './function/addusertogroup/resource';
66
import { removeuserfromgroup } from './function/removeuserfromgroup/resource';
77
import { defineBackend } from '@aws-amplify/backend';
8-
import { Duration } from 'aws-cdk-lib';
8+
import { Duration, aws_iam } from 'aws-cdk-lib';
99
import {
1010
OAuthScope,
1111
UserPoolClientIdentityProvider,
@@ -114,3 +114,23 @@ backend.removeuserfromgroup.addEnvironment(
114114
'AUTH_MEDIAVAULT1F08412D_USERPOOLID',
115115
backend.auth.resources.userPool.userPoolId
116116
);
117+
backend.addusertogroup.resources.lambda.addToRolePolicy(
118+
new aws_iam.PolicyStatement({
119+
actions: [
120+
"cognito-idp:CreateGroup",
121+
"cognito-idp:DeleteGroup",
122+
"cognito-idp:UpdateGroup",
123+
],
124+
resources: [backend.auth.resources.userPool.userPoolArn],
125+
})
126+
);
127+
backend.removeuserfromgroup.resources.lambda.addToRolePolicy(
128+
new aws_iam.PolicyStatement({
129+
actions: [
130+
"cognito-idp:CreateGroup",
131+
"cognito-idp:DeleteGroup",
132+
"cognito-idp:UpdateGroup",
133+
],
134+
resources: [backend.auth.resources.userPool.userPoolArn],
135+
})
136+
);

amplify-migration-apps/store-locator/_snapshot.post.generate/amplify/auth/resource.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,5 @@ export const auth = defineAuth({
2525
allow
2626
.resource(storelocator41a9495f41a9495fPostConfirmation)
2727
.to(['addUserToGroup']),
28-
allow
29-
.resource(storelocator41a9495f41a9495fPostConfirmation)
30-
.to(['manageGroups']),
3128
],
3229
});

amplify-migration-apps/store-locator/_snapshot.post.generate/amplify/backend.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
12
import { auth } from './auth/resource';
23
import { storelocator41a9495f41a9495fPostConfirmation } from './auth/storelocator41a9495f41a9495fPostConfirmation/resource';
34
import { defineGeo } from './geo/resource';
45
import { defineBackend } from '@aws-amplify/backend';
5-
import { Duration } from 'aws-cdk-lib';
6+
import { Duration, aws_iam } from 'aws-cdk-lib';
67

78
const backend = defineBackend({
89
auth,
@@ -32,3 +33,13 @@ userPool.addClient('NativeAppClient', {
3233
});
3334
const branchName = process.env.AWS_BRANCH ?? 'sandbox';
3435
backend.storelocator41a9495f41a9495fPostConfirmation.resources.cfnResources.cfnFunction.functionName = `storelocator41a9495f41a9495fPostConfirmation-${branchName}`;
36+
37+
backend.storelocator41a9495f41a9495fPostConfirmation.resources.lambda.addToRolePolicy(
38+
new aws_iam.PolicyStatement({
39+
actions: [
40+
"cognito-idp:GetGroup",
41+
"cognito-idp:CreateGroup"
42+
],
43+
resources: [backend.auth.resources.userPool.userPoolArn],
44+
})
45+
);

packages/amplify-cli/src/commands/gen2-migration/generate/amplify/function/function.generator.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ export class FunctionGenerator implements Planner {
631631
}
632632
}
633633

634-
return resolveAuthTriggerAccess(cognitoActions);
634+
return resolveAuthAccess(cognitoActions);
635635
}
636636

637637
/**
@@ -1077,6 +1077,10 @@ const AUTH_ACTION_MAPPING: Readonly<Record<string, keyof AuthPermissions>> = {
10771077
'cognito-idp:UpdateUserAttributes': 'updateUserAttributes',
10781078
'cognito-idp:SetUserMFAPreference': 'setUserMfaPreference',
10791079
'cognito-idp:SetUserSettings': 'setUserSettings',
1080+
'cognito-idp:GetGroup': 'manageGroups',
1081+
'cognito-idp:CreateGroup': 'manageGroups',
1082+
'cognito-idp:DeleteGroup': 'manageGroups',
1083+
'cognito-idp:UpdateGroup': 'manageGroups',
10801084
};
10811085

10821086
function resolveAuthAccess(cognitoActions: string[]): AuthPermissions {
@@ -1100,35 +1104,6 @@ function resolveAuthAccess(cognitoActions: string[]): AuthPermissions {
11001104
return result as AuthPermissions;
11011105
}
11021106

1103-
/**
1104-
* Maps cognito-idp IAM actions from auth-trigger CFN templates to Gen2 auth permissions.
1105-
*
1106-
* Auth trigger policies (e.g., "Add User To Group") use actions like `GetGroup` and
1107-
* `CreateGroup` that aren't in the standard `AUTH_ACTION_MAPPING` (which covers actions
1108-
* from function-level `AmplifyResourcesPolicy`). This function extends the base mapping
1109-
* with trigger-specific actions that map to `manageGroups`.
1110-
*/
1111-
const AUTH_TRIGGER_ACTION_MAPPING: Readonly<Record<string, keyof AuthPermissions>> = {
1112-
...AUTH_ACTION_MAPPING,
1113-
'cognito-idp:GetGroup': 'manageGroups',
1114-
'cognito-idp:CreateGroup': 'manageGroups',
1115-
'cognito-idp:DeleteGroup': 'manageGroups',
1116-
'cognito-idp:UpdateGroup': 'manageGroups',
1117-
};
1118-
1119-
function resolveAuthTriggerAccess(cognitoActions: string[]): AuthPermissions {
1120-
if (cognitoActions.length === 0) return {};
1121-
const result: Record<string, boolean> = {};
1122-
1123-
for (const action of cognitoActions) {
1124-
if (AUTH_TRIGGER_ACTION_MAPPING[action]) {
1125-
result[AUTH_TRIGGER_ACTION_MAPPING[action]] = true;
1126-
}
1127-
}
1128-
1129-
return result as AuthPermissions;
1130-
}
1131-
11321107
// ── Auth trigger suffix mapping ───────────────────────────────────
11331108

11341109
const TRIGGER_SUFFIX_TO_EVENT: Readonly<Record<string, AuthTriggerEvent>> = {

0 commit comments

Comments
 (0)