@@ -56,6 +56,11 @@ Parameters:
56
56
Description : The name of the DynamoDB Customers table.
57
57
Default : ' DevPortalCustomers'
58
58
59
+ DevPortalPreLoginAccountsTableName :
60
+ Type : String
61
+ Description : The name of the DynamoDB PreLoginAccounts table.
62
+ Default : ' DevPortalPreLoginAccounts'
63
+
59
64
DevPortalAdminEmail :
60
65
Type : String
61
66
Description : The email address where user submitted feedback notifications get sent.
@@ -638,6 +643,20 @@ Resources:
638
643
ReadCapacityUnits : 5
639
644
WriteCapacityUnits : 5
640
645
646
+ PreLoginAccountsTable :
647
+ Type : AWS::DynamoDB::Table
648
+ Properties :
649
+ TableName : !Ref DevPortalPreLoginAccountsTableName
650
+ AttributeDefinitions :
651
+ - AttributeName : UserId
652
+ AttributeType : S
653
+ KeySchema :
654
+ - AttributeName : UserId
655
+ KeyType : HASH
656
+ ProvisionedThroughput :
657
+ ReadCapacityUnits : 5
658
+ WriteCapacityUnits : 5
659
+
641
660
FeedbackTable :
642
661
Type : AWS::DynamoDB::Table
643
662
Condition : EnableFeedbackSubmission
@@ -737,6 +756,15 @@ Resources:
737
756
- !Ref ' AWS::AccountId'
738
757
- :table/
739
758
- !Ref CustomersTable
759
+ - Effect : Allow
760
+ Action :
761
+ - dynamodb:GetItem
762
+ - dynamodb:Query
763
+ - dynamodb:Scan
764
+ - dynamodb:PutItem
765
+ - dynamodb:UpdateItem
766
+ - dynamodb:DeleteItem
767
+ Resource : !GetAtt PreLoginAccountsTable.Arn
740
768
- Effect : Allow
741
769
Action :
742
770
- dynamodb:Query
@@ -777,8 +805,18 @@ Resources:
777
805
- sns:Publish
778
806
Resource : !Ref FeedbackSubmittedSNSTopic
779
807
- !Ref ' AWS::NoValue'
808
+ - Effect : Allow
809
+ Action :
810
+ - cognito-idp:ListUsers
811
+ - cognito-idp:ListUsersInGroup
812
+ - cognito-idp:AdminAddUserToGroup
813
+ - cognito-idp:AdminCreateUser
814
+ - cognito-idp:AdminDeleteUser
815
+ - cognito-idp:AdminGetUser
816
+ - cognito-idp:AdminListGroupsForUser
817
+ Resource : !GetAtt CognitoUserPool.Arn
780
818
781
- CognitoStrategyLambdaExecutionRole :
819
+ CognitoPreSignupTriggerExecutionRole :
782
820
Type : AWS::IAM::Role
783
821
Properties :
784
822
AssumeRolePolicyDocument :
@@ -801,6 +839,74 @@ Resources:
801
839
- logs:PutLogEvents
802
840
Resource : arn:aws:logs:*:*:*
803
841
842
+ CognitoPostConfirmationTriggerExecutionRole :
843
+ Type : AWS::IAM::Role
844
+ Properties :
845
+ AssumeRolePolicyDocument :
846
+ Version : ' 2012-10-17'
847
+ Statement :
848
+ Effect : Allow
849
+ Principal :
850
+ Service : lambda.amazonaws.com
851
+ Action : sts:AssumeRole
852
+ Path : ' /'
853
+ Policies :
854
+ - PolicyName : root
855
+ PolicyDocument :
856
+ Version : ' 2012-10-17'
857
+ Statement :
858
+ - Effect : Allow
859
+ Action :
860
+ - logs:CreateLogGroup
861
+ - logs:CreateLogStream
862
+ - logs:PutLogEvents
863
+ Resource : arn:aws:logs:*:*:*
864
+ - Effect : Allow
865
+ Action :
866
+ - dynamodb:PutItem
867
+ Resource : !GetAtt PreLoginAccountsTable.Arn
868
+ - Effect : Allow
869
+ Action :
870
+ - cognito-idp:AdminAddUserToGroup
871
+ Resource : !GetAtt CognitoUserPool.Arn
872
+
873
+ CognitoPostAuthenticationTriggerExecutionRole :
874
+ Type : AWS::IAM::Role
875
+ Properties :
876
+ AssumeRolePolicyDocument :
877
+ Version : ' 2012-10-17'
878
+ Statement :
879
+ Effect : Allow
880
+ Principal :
881
+ Service : lambda.amazonaws.com
882
+ Action : sts:AssumeRole
883
+ Path : ' /'
884
+ Policies :
885
+ - PolicyName : root
886
+ PolicyDocument :
887
+ Version : ' 2012-10-17'
888
+ Statement :
889
+ - Effect : Allow
890
+ Action :
891
+ - logs:CreateLogGroup
892
+ - logs:CreateLogStream
893
+ - logs:PutLogEvents
894
+ Resource : arn:aws:logs:*:*:*
895
+ - Effect : Allow
896
+ Action :
897
+ - dynamodb:Scan
898
+ - dynamodb:PutItem
899
+ Resource : !GetAtt CustomersTable.Arn
900
+ - Effect : Allow
901
+ Action :
902
+ - dynamodb:GetItem
903
+ - dynamodb:PutItem
904
+ Resource : !GetAtt PreLoginAccountsTable.Arn
905
+ - Effect : Allow
906
+ Action :
907
+ - cognito-idp:AdminAddUserToGroup
908
+ Resource : !GetAtt CognitoUserPool.Arn
909
+
804
910
CatalogUpdaterLambdaExecutionRole :
805
911
Type : AWS::IAM::Role
806
912
Properties :
@@ -968,11 +1074,41 @@ Resources:
968
1074
- !Ref ApiGatewayApi
969
1075
- ' /*/*'
970
1076
971
- LambdaCognitoUserPoolExecutionPermission :
1077
+ CognitoPreSignupTriggerFnExecutionPermission :
972
1078
Type : AWS::Lambda::Permission
973
1079
Properties :
974
1080
Action : lambda:InvokeFunction
975
- FunctionName : !GetAtt CognitoUserPoolsConfirmationStrategyFunction.Arn
1081
+ FunctionName : !GetAtt CognitoPreSignupTriggerFn.Arn
1082
+ Principal : cognito-idp.amazonaws.com
1083
+ SourceArn : !Join
1084
+ - ' '
1085
+ - - 'arn:aws:cognito-idp:'
1086
+ - !Ref ' AWS::Region'
1087
+ - ' :'
1088
+ - !Ref ' AWS::AccountId'
1089
+ - ' :userpool/'
1090
+ - !Ref CognitoUserPool
1091
+
1092
+ CognitoPostConfirmationTriggerFnExecutionPermission :
1093
+ Type : AWS::Lambda::Permission
1094
+ Properties :
1095
+ Action : lambda:InvokeFunction
1096
+ FunctionName : !GetAtt CognitoPostConfirmationTriggerFn.Arn
1097
+ Principal : cognito-idp.amazonaws.com
1098
+ SourceArn : !Join
1099
+ - ' '
1100
+ - - 'arn:aws:cognito-idp:'
1101
+ - !Ref ' AWS::Region'
1102
+ - ' :'
1103
+ - !Ref ' AWS::AccountId'
1104
+ - ' :userpool/'
1105
+ - !Ref CognitoUserPool
1106
+
1107
+ CognitoPostAuthenticationTriggerFnExecutionPermission :
1108
+ Type : AWS::Lambda::Permission
1109
+ Properties :
1110
+ Action : lambda:InvokeFunction
1111
+ FunctionName : !GetAtt CognitoPostAuthenticationTriggerFn.Arn
976
1112
Principal : cognito-idp.amazonaws.com
977
1113
SourceArn : !Join
978
1114
- ' '
@@ -1030,10 +1166,15 @@ Resources:
1030
1166
WEBSITE_BUCKET_NAME : !Ref DevPortalSiteS3BucketName
1031
1167
StaticBucketName : !Ref ArtifactsS3BucketName
1032
1168
CustomersTableName : !Ref DevPortalCustomersTableName
1169
+ PreLoginAccountsTableName : !Ref DevPortalPreLoginAccountsTableName
1033
1170
CatalogUpdaterFunctionArn : !GetAtt CatalogUpdaterLambdaFunction.Arn
1034
1171
FeedbackTableName : !Ref DevPortalFeedbackTableName
1035
1172
FeedbackSnsTopicArn :
1036
1173
!If [EnableFeedbackSubmission, !Ref FeedbackSubmittedSNSTopic, '']
1174
+ UserPoolId : !Ref CognitoUserPool
1175
+ AdminsGroupName : !Join ['', [!Ref 'AWS::StackName', 'AdminsGroup']]
1176
+ RegisteredGroupName : !Sub '${AWS::StackName}-RegisteredGroup'
1177
+ DevelopmentMode : !Ref DevelopmentMode
1037
1178
# Adds the API as a trigger
1038
1179
Events :
1039
1180
ProxyApiRoot :
@@ -1063,24 +1204,86 @@ Resources:
1063
1204
Layers :
1064
1205
- !Ref LambdaCommonLayer
1065
1206
1066
- CognitoUserPoolsConfirmationStrategyFunction :
1207
+ CognitoPreSignupTriggerFn :
1067
1208
Type : AWS::Serverless::Function
1068
1209
Properties :
1069
- CodeUri : ../lambdas/cognito-user-pools-confirmation-strategy
1210
+ FunctionName : !Sub '${AWS::StackName}-CognitoPreSignupTriggerFn'
1211
+ CodeUri : ../lambdas/cognito-pre-signup-trigger
1070
1212
Handler : index.handler
1071
1213
MemorySize : 128
1072
- Role : !GetAtt CognitoStrategyLambdaExecutionRole.Arn
1073
- Runtime : nodejs12.x
1214
+ Role : !GetAtt CognitoPreSignupTriggerExecutionRole.Arn
1215
+ Runtime : nodejs10.x
1216
+ Timeout : 3
1217
+ Environment :
1218
+ Variables :
1219
+ AccountRegistrationMode : !Ref AccountRegistrationMode
1220
+ Layers :
1221
+ - !Ref LambdaCommonLayer
1222
+
1223
+ CognitoPostConfirmationTriggerFn :
1224
+ Type : AWS::Serverless::Function
1225
+ Properties :
1226
+ FunctionName : !Sub '${AWS::StackName}-CognitoPostConfirmationTriggerFn'
1227
+ CodeUri : ../lambdas/cognito-post-confirmation-trigger
1228
+ Handler : index.handler
1229
+ MemorySize : 128
1230
+ Role : !GetAtt CognitoPostConfirmationTriggerExecutionRole.Arn
1231
+ Runtime : nodejs10.x
1232
+ Timeout : 3
1233
+ Environment :
1234
+ Variables :
1235
+ AccountRegistrationMode : !Ref AccountRegistrationMode
1236
+ PreLoginAccountsTableName : !Ref DevPortalPreLoginAccountsTableName
1237
+ RegisteredGroupName : !Sub '${AWS::StackName}-RegisteredGroup'
1238
+ Layers :
1239
+ - !Ref LambdaCommonLayer
1240
+
1241
+ CognitoPostAuthenticationTriggerFn :
1242
+ Type : AWS::Serverless::Function
1243
+ Properties :
1244
+ FunctionName : !Sub '${AWS::StackName}-CognitoPostAuthenticationTriggerFn'
1245
+ CodeUri : ../lambdas/cognito-post-authentication-trigger
1246
+ Handler : index.handler
1247
+ MemorySize : 128
1248
+ Role : !GetAtt CognitoPostAuthenticationTriggerExecutionRole.Arn
1249
+ Runtime : nodejs10.x
1074
1250
Timeout : 3
1251
+ Environment :
1252
+ Variables :
1253
+ CustomersTableName : !Ref DevPortalCustomersTableName
1254
+ PreLoginAccountsTableName : !Ref DevPortalPreLoginAccountsTableName
1255
+ RegisteredGroupName : !Sub '${AWS::StackName}-RegisteredGroup'
1075
1256
Layers :
1076
1257
- !Ref LambdaCommonLayer
1077
1258
1078
1259
CognitoUserPool :
1079
1260
Type : AWS::Cognito::UserPool
1080
1261
Properties :
1081
1262
UserPoolName : !Ref CognitoIdentityPoolName
1263
+ # Lambda trigger caveats:
1264
+ #
1265
+ # - We can't use the functions' ARNs here, because there would be a
1266
+ # circular dependency: some functions reference either the UserPool or
1267
+ # UserPoolGroups within it.
1268
+ #
1269
+ # - You must declare an AWS::Lambda::Permission for each lambda here, or
1270
+ # else calls from Cognito will fail with an AccessDeniedException. See
1271
+ # `CognitoPreSignupTriggerFnExecutionPermission` as an example. More
1272
+ # reading: <https://stackoverflow.com/a/42460847> and
1273
+ # <https://forums.aws.amazon.com/thread.jspa?messageID=748566#748566>
1082
1274
LambdaConfig :
1083
- PreSignUp : !GetAtt CognitoUserPoolsConfirmationStrategyFunction.Arn
1275
+ PreSignUp : !Join
1276
+ - ' '
1277
+ - - !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:'
1278
+ - !Sub ' ${AWS::StackName}-CognitoPreSignupTriggerFn'
1279
+ PostConfirmation : !Join
1280
+ - ' '
1281
+ - - !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:'
1282
+ - !Sub ' ${AWS::StackName}-CognitoPostConfirmationTriggerFn'
1283
+ PostAuthentication : !Join
1284
+ - ' '
1285
+ - - !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:'
1286
+ - !Sub ' ${AWS::StackName}-CognitoPostAuthenticationTriggerFn'
1084
1287
Policies :
1085
1288
PasswordPolicy :
1086
1289
MinimumLength : 12
@@ -1264,6 +1467,7 @@ Resources:
1264
1467
Roles :
1265
1468
authenticated : !GetAtt CognitoAuthenticatedRole.Arn
1266
1469
1470
+ # Every logged-in Cognito user is "authenticated".
1267
1471
CognitoAuthenticatedRole :
1268
1472
Type : AWS::IAM::Role
1269
1473
Properties :
@@ -1281,6 +1485,42 @@ Resources:
1281
1485
' cognito-identity.amazonaws.com:amr ' : authenticated
1282
1486
Policies :
1283
1487
- PolicyName : CognitoAuthenticatedRole
1488
+ PolicyDocument :
1489
+ Version : ' 2012-10-17'
1490
+ Statement :
1491
+ - Effect : Allow
1492
+ Action :
1493
+ - execute-api:Invoke
1494
+ Resource : !Join
1495
+ - ' '
1496
+ - - 'arn:aws:execute-api:'
1497
+ - !Ref ' AWS::Region'
1498
+ - ' :'
1499
+ - !Ref ' AWS::AccountId'
1500
+ - ' :'
1501
+ - !Ref ApiGatewayApi
1502
+ - /prod/*/signin
1503
+ Path : ' /'
1504
+
1505
+ # A logged-in Cognito user, who is not in a "pending" (invite or request)
1506
+ # state, is "registered".
1507
+ CognitoRegisteredRole :
1508
+ Type : AWS::IAM::Role
1509
+ Properties :
1510
+ AssumeRolePolicyDocument :
1511
+ Version : ' 2012-10-17'
1512
+ Statement :
1513
+ - Effect : Allow
1514
+ Principal :
1515
+ Federated : cognito-identity.amazonaws.com
1516
+ Action : sts:AssumeRoleWithWebIdentity
1517
+ Condition :
1518
+ StringEquals :
1519
+ ' cognito-identity.amazonaws.com:aud ' : !Ref CognitoIdentityPool
1520
+ ' ForAnyValue:StringLike ' :
1521
+ ' cognito-identity.amazonaws.com:amr ' : authenticated
1522
+ Policies :
1523
+ - PolicyName : CognitoRegisteredRole
1284
1524
PolicyDocument :
1285
1525
Version : ' 2012-10-17'
1286
1526
Statement :
@@ -1326,7 +1566,7 @@ Resources:
1326
1566
' ForAnyValue:StringLike ' :
1327
1567
' cognito-identity.amazonaws.com:amr ' : authenticated
1328
1568
Policies :
1329
- - PolicyName : CognitoAuthenticatedRole
1569
+ - PolicyName : CognitoAdminRole
1330
1570
PolicyDocument :
1331
1571
Version : ' 2012-10-17'
1332
1572
Statement :
@@ -1354,6 +1594,15 @@ Resources:
1354
1594
RoleArn : !GetAtt CognitoAdminRole.Arn
1355
1595
UserPoolId : !Ref CognitoUserPool
1356
1596
1597
+ CognitoRegisteredGroup :
1598
+ Type : AWS::Cognito::UserPoolGroup
1599
+ Properties :
1600
+ Description : ' Registered users in the developer portal'
1601
+ GroupName : !Sub '${AWS::StackName}-RegisteredGroup'
1602
+ Precedence : 1
1603
+ RoleArn : !GetAtt CognitoRegisteredRole.Arn
1604
+ UserPoolId : !Ref CognitoUserPool
1605
+
1357
1606
CatalogUpdaterLambdaFunction :
1358
1607
Type : AWS::Serverless::Function
1359
1608
Properties :
0 commit comments