Skip to content

Commit c6fc838

Browse files
feat: cognito + s3 + dyanmodb lambda trigger support (#1783)
1 parent 3b230a2 commit c6fc838

File tree

119 files changed

+7746
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+7746
-283
lines changed

packages/amplify-category-auth/commands/auth/enable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = {
3131
return providerController.addResource(context, category, result.service);
3232
})
3333
.then((resourceName) => {
34+
if (context.amplify.auth && context.amplify.auth.dependsOn) {
35+
options.dependsOn = context.amplify.auth.dependsOn;
36+
}
3437
amplify.updateamplifyMetaAfterResourceAdd(category, resourceName, options);
3538
const { print } = context;
3639
print.success(`Successfully added resource ${resourceName} locally`);

packages/amplify-category-auth/commands/auth/push.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const subcommand = 'push';
22
const category = 'auth';
3+
const { uploadFiles } = require('../../provider-utils/awscloudformation/utils/trigger-file-uploader');
34

45
module.exports = {
56
name: subcommand,
@@ -8,6 +9,9 @@ module.exports = {
89
const resourceName = parameters.first;
910
context.amplify.constructExeInfo(context);
1011
return amplify.pushResources(context, category, resourceName)
12+
.then(async () => {
13+
await uploadFiles(context);
14+
})
1115
.catch((err) => {
1216
context.print.info(err.stack);
1317
context.print.error('There was an error pushing the auth resource');

packages/amplify-category-auth/commands/auth/update.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ module.exports = {
4949
return providerController.updateResource(context, category, options);
5050
})
5151
.then((resourceName) => { // eslint-disable-line no-shadow
52-
amplify.updateamplifyMetaAfterResourceUpdate(category, resourceName, options);
52+
if (context.amplify.auth && context.amplify.auth.dependsOn) {
53+
amplify.updateamplifyMetaAfterResourceUpdate(category, resourceName, 'dependsOn', context.amplify.auth.dependsOn);
54+
}
5355
const { print } = context;
5456
print.success(`Successfully updated resource ${resourceName} locally`);
5557
print.info('');

packages/amplify-category-auth/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,25 @@ async function checkRequirements(requirements, context) {
188188
async function initEnv(context) {
189189
const { amplify } = context;
190190
const { resourcesToBeCreated, resourcesToBeDeleted, resourcesToBeUpdated } = await amplify.getResourceStatus('auth');
191+
let toBeCreated = [];
192+
let toBeDeleted = [];
193+
let toBeUpdated = [];
191194

192-
resourcesToBeDeleted.forEach((authResource) => {
195+
if (resourcesToBeCreated && resourcesToBeCreated.length > 0) {
196+
toBeCreated = resourcesToBeCreated.filter(a => a.category === 'auth');
197+
}
198+
if (resourcesToBeDeleted && resourcesToBeDeleted.length > 0) {
199+
toBeDeleted = resourcesToBeDeleted.filter(b => b.category === 'auth');
200+
}
201+
if (resourcesToBeUpdated && resourcesToBeUpdated.length > 0) {
202+
toBeUpdated = resourcesToBeUpdated.filter(c => c.category === 'auth');
203+
}
204+
205+
toBeDeleted.forEach((authResource) => {
193206
amplify.removeResourceParameters(context, 'auth', authResource.resourceName);
194207
});
195208

196-
const tasks = resourcesToBeCreated.concat(resourcesToBeUpdated);
209+
const tasks = toBeCreated.concat(toBeUpdated);
197210

198211
const authTasks = tasks.map((authResource) => {
199212
const { resourceName } = authResource;

packages/amplify-category-auth/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
"test-ci": "jest --ci -i"
1414
},
1515
"dependencies": {
16+
"amplify-category-function": "^1.4.1",
17+
"aws-sdk": "^2.475.0",
1618
"chalk": "^2.4.1",
17-
"chalk-pipe": "^1.2.0",
19+
"chalk-pipe": "^2.0.0",
1820
"eslint": "^4.19.1",
1921
"fs-extra": "^7.0.0",
2022
"inquirer": "6.3.1",
2123
"jest": "^23.5.0",
2224
"lodash": "^4.17.10",
25+
"mime-types": "^2.1.24",
2326
"opn": "^5.3.0",
27+
"ora": "^3.4.0",
2428
"promise-sequential": "^1.1.1",
2529
"uuid": "^2.0.3"
2630
},

packages/amplify-category-auth/provider-utils/awscloudformation/assets/cognito-defaults.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@ const roles = {
2929

3030
const generalDefaults = projectName => ({
3131
resourceName: `${projectName}${sharedId}`,
32+
resourceNameTruncated: `${projectName.substring(0, 6)}${sharedId}`,
3233
authSelections: 'identityPoolAndUserPool',
3334
...roles,
3435
});
3536

3637
const userPoolDefaults = (projectName) => {
3738
const projectNameTruncated = `${projectName.substring(0, 6)}${sharedId}`;
3839
return ({
40+
resourceNameTruncated: `${projectName.substring(0, 6)}${sharedId}`,
3941
userPoolName: `${projectName}_userpool_${sharedId}`,
4042
autoVerifiedAttributes: ['email'],
4143
mfaConfiguration: 'OFF',
4244
mfaTypes: ['SMS Text Message'],
43-
roleName: `${projectNameTruncated}_sns-role`,
44-
roleExternalId: `${projectNameTruncated}_role_external_id`,
45-
policyName: `${projectNameTruncated}-sns-policy`,
4645
smsAuthenticationMessage: 'Your authentication code is {####}',
4746
smsVerificationMessage: 'Your verification code is {####}',
4847
emailVerificationSubject: 'Your verification code',
@@ -58,12 +57,7 @@ const userPoolDefaults = (projectName) => {
5857
userpoolClientWriteAttributes: ['email'],
5958
userpoolClientReadAttributes: ['email'],
6059
mfaLambdaRole: `${projectNameTruncated}_totp_lambda_role`,
61-
mfaLambdaLogPolicy: `${projectNameTruncated}_totp_lambda_log_policy`,
62-
mfaPassRolePolicy: `${projectNameTruncated}_totp_pass_role_policy`,
63-
mfaLambdaIAMPolicy: `${projectNameTruncated}_totp_lambda_iam_policy`,
6460
userpoolClientLambdaRole: `${projectNameTruncated}_userpoolclient_lambda_role`,
65-
userpoolClientLogPolicy: `${projectNameTruncated}_userpoolclient_lambda_log_policy`,
66-
userpoolClientLambdaPolicy: `${projectNameTruncated}_userpoolclient_lambda_iam_policy`,
6761
userpoolClientSetAttributes: false,
6862
});
6963
};
@@ -76,15 +70,11 @@ const withSocialDefaults = projectName => ({
7670
});
7771

7872
const identityPoolDefaults = (projectName) => {
79-
const projectNameTruncated = `${projectName.substring(0, 6)}_${sharedId}`;
73+
const projectNameTruncated = `${projectName.substring(0, 6)}${sharedId}`;
8074
return ({
8175
identityPoolName: `${projectName}_identitypool_${sharedId}`,
8276
allowUnauthenticatedIdentities: booleanOptions.find(b => b.value === false).value,
83-
lambdaLogPolicy: `${projectNameTruncated}_lambda_log_policy`,
8477
openIdLambdaRoleName: `${projectNameTruncated}_openid_lambda_role`,
85-
openIdRolePolicy: `${projectNameTruncated}_openid_pass_role_policy`,
86-
openIdLambdaIAMPolicy: `${projectNameTruncated}_openid_lambda_iam_policy`,
87-
openIdLogPolicy: `${projectNameTruncated}_openid_lambda_log_policy`,
8878
});
8979
};
9080

packages/amplify-category-auth/provider-utils/awscloudformation/assets/string-maps.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,66 @@ const oAuthScopes = [
461461
},
462462
];
463463

464+
const capabilities = [
465+
{
466+
name: 'Add Google reCaptcha Challenge',
467+
value: 'mfaWithCaptcha',
468+
triggers: {
469+
DefineAuthChallenge: ['captcha-define-challenge'],
470+
CreateAuthChallenge: ['captcha-create-challenge'],
471+
VerifyAuthChallengeResponse: ['captcha-verify'],
472+
},
473+
},
474+
{
475+
name: 'Email Verification Link with Redirect',
476+
value: 'confirmationRedirect',
477+
triggers: {
478+
CustomMessage: ['verification-link'],
479+
},
480+
},
481+
{
482+
name: 'Add User to Group',
483+
value: 'addUserToGroup',
484+
triggers: {
485+
PostConfirmation: ['add-to-group'],
486+
},
487+
},
488+
{
489+
name: 'Email Domain Filtering (blacklist)',
490+
value: 'emailBlacklist',
491+
triggers: {
492+
PreSignup: ['email-filter-blacklist'],
493+
},
494+
},
495+
{
496+
name: 'Email Domain Filtering (whitelist)',
497+
value: 'emailWhitelist',
498+
triggers: {
499+
PreSignup: ['email-filter-whitelist'],
500+
},
501+
},
502+
{
503+
name: 'Custom Auth Challenge Flow (basic scaffolding - not for production)',
504+
value: 'customAuthScaffolding',
505+
triggers: {
506+
DefineAuthChallenge: ['boilerplate-define-challenge'],
507+
CreateAuthChallenge: ['boilerplate-create-challenge'],
508+
VerifyAuthChallengeResponse: ['boilerplate-verify'],
509+
},
510+
},
511+
];
512+
513+
const additonalConfigMap = [
514+
{
515+
name: 'No, I am done.',
516+
value: [],
517+
},
518+
{
519+
name: 'Yes, I want to make some additional changes.',
520+
value: ['requiredAttributes', 'triggers'],
521+
},
522+
];
523+
464524
const disableOptionsOnEdit = () => {
465525
mfaOptions.find(i => i.value === 'ON').disabled = true;
466526
};
@@ -487,6 +547,8 @@ const getAllMaps = ((edit) => {
487547
authorizeScopes,
488548
attributeProviderMap,
489549
updateFlowMap,
550+
capabilities,
551+
additonalConfigMap,
490552
};
491553
});
492554

@@ -510,4 +572,6 @@ module.exports = {
510572
messages,
511573
attributeProviderMap,
512574
updateFlowMap,
575+
capabilities,
576+
additonalConfigMap,
513577
};

0 commit comments

Comments
 (0)