diff --git a/cloudformation/template.yaml b/cloudformation/template.yaml index 54d49006c..e4acb5246 100644 --- a/cloudformation/template.yaml +++ b/cloudformation/template.yaml @@ -93,6 +93,10 @@ Parameters: Type: String Description: The Domain Name (or Prefix) at which your Cognito Hosted UI is located. This should be regionally unique. + ExistingCognitoUserPool: + Type: String + Description: The existing User Pool ID. Leave blank to create a new User Pool. + # CognitoDomainAcmCertArn: # Type: String # Description: Doesn't yet do anything. Oh well. @@ -134,6 +138,7 @@ Conditions: DevelopmentMode: !Equals [!Ref DevelopmentMode, 'true'] NotDevelopmentMode: !Not [!Condition DevelopmentMode] InUSEastOne: !Equals [!Ref 'AWS::Region', 'us-east-1'] + CreateCognitoUserPool: !Equals [!Ref ExistingCognitoUserPool, ''] Resources: ApiGatewayApi: @@ -564,6 +569,7 @@ Resources: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${CloudFrontOriginAccessIdentity} + ArtifactsS3Bucket: Type: AWS::S3::Bucket Properties: @@ -960,7 +966,7 @@ Resources: - ':' - !Ref 'AWS::AccountId' - ':userpool/' - - !Ref CognitoUserPool + - !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] LambdaSNSExecutionPermission: Type: AWS::Lambda::Permission @@ -1043,6 +1049,7 @@ Resources: CognitoUserPool: Type: AWS::Cognito::UserPool + Condition: CreateCognitoUserPool Properties: UserPoolName: !Ref CognitoIdentityPoolName LambdaConfig: @@ -1064,7 +1071,7 @@ Resources: # However, when this is updated and changes, the CUPCS custom resource doesn't re-run, and so a bunch of vital # settings won't be set, e.g., CallbackURL. Properties: - UserPoolId: !Ref CognitoUserPool + UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] ClientName: CognitoIdentityPool GenerateSecret: false RefreshTokenValidity: 30 @@ -1116,7 +1123,7 @@ Resources: Properties: Timeout: 360 ServiceToken: !GetAtt CognitoUserPoolClientSettingsBackingFn.Arn - UserPoolId: !Ref CognitoUserPool + UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] UserPoolClientId: !Ref CognitoUserPoolClient SupportedIdentityProviders: [ "COGNITO" ] # should (eventually) allow people to add values CallbackURL: !If [ DevelopmentMode, @@ -1193,6 +1200,7 @@ Resources: CognitoUserPoolDomain: Type: AWS::CloudFormation::CustomResource + Condition: CreateCognitoUserPool Properties: Timeout: 360 ServiceToken: !GetAtt CognitoUserPoolDomainBackingFn.Arn @@ -1211,7 +1219,7 @@ Resources: - - cognito-idp. - !Ref 'AWS::Region' - .amazonaws.com/ - - !Ref CognitoUserPool + - !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] CognitoIdentityPoolRoles: Type: AWS::Cognito::IdentityPoolRoleAttachment @@ -1308,7 +1316,7 @@ Resources: # since admin group has a precedence of 0, it takes priority Precedence: 0 RoleArn: !GetAtt CognitoAdminRole.Arn - UserPoolId: !Ref CognitoUserPool + UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] CatalogUpdaterLambdaFunction: Type: AWS::Serverless::Function @@ -1354,9 +1362,9 @@ Resources: RestApiId: !Ref ApiGatewayApi Region: !Ref 'AWS::Region' IdentityPoolId: !Ref CognitoIdentityPool - UserPoolId: !Ref CognitoUserPool + UserPoolId: !If [CreateCognitoUserPool, !Ref CognitoUserPool, !Ref ExistingCognitoUserPool] UserPoolClientId: !Ref CognitoUserPoolClient - UserPoolDomain: !GetAtt CognitoUserPoolDomain.FullUrl + UserPoolDomain: !If [ CreateCognitoUserPool, !GetAtt CognitoUserPoolDomain.FullUrl, !Ref CognitoDomainNameOrPrefix ] MarketplaceSuffix: !Ref MarketplaceSubscriptionTopicProductCode RebuildToken: !Ref StaticAssetRebuildToken RebuildMode: !Ref StaticAssetRebuildMode diff --git a/dev-portal/README.md b/dev-portal/README.md index bb2b58b2f..7ae10b02f 100644 --- a/dev-portal/README.md +++ b/dev-portal/README.md @@ -25,9 +25,13 @@ module.exports = { // Change the name of the customer's table. Useful for multiple stacks. Defaults to `DevPortalCustomers` // customersTableName: `DevPortalCustomers`, + // Optional Existing Cognito User Pool. This parameter alters the value of the CognitoDomainName value. See below. + // cognitoUserPool: "eu-west-1_XXX", + // Turns on cognito hosted sign in / sign up UI; Defaults to `` (blank string) + // Important: If 'cognitoUserPool' is provided, this needs to be the full URL of the Cognito hosted UI (e.g. https://my.auth.org or https://myauth.auth.eu-west-1.amazoncognito.com) // cognitoDomainName: `auth-url`, - + // Set this to overwrite-content if you want to reset your custom content back to the defaults. Defaults to `` // staticAssetRebuildMode: `overwrite-content` // ONLY SET diff --git a/dev-portal/scripts/deploy-stack.js b/dev-portal/scripts/deploy-stack.js index 90220df84..3814047f5 100644 --- a/dev-portal/scripts/deploy-stack.js +++ b/dev-portal/scripts/deploy-stack.js @@ -25,10 +25,14 @@ const staticAssetRebuildMode = deployerConfig.staticAssetRebuildMode || '' const awsSamCliProfile = deployerConfig.awsSamCliProfile; const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : '' +// Existing Cognito User Pool configuration +const existingCognitoUserPool = deployerConfig.cognitoUserPool || ""; + + function main() { Promise.resolve() .then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket} ${profileOption}`, true)) -.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true)) +.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides ExistingCognitoUserPool="${existingCognitoUserPool}" StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true)) .then(() => writeConfig(true)) .then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green())) .catch(err => { diff --git a/lambdas/static-asset-uploader/build/asset-manifest.json b/lambdas/static-asset-uploader/build/asset-manifest.json index 159c95b0f..34ed3e41a 100644 --- a/lambdas/static-asset-uploader/build/asset-manifest.json +++ b/lambdas/static-asset-uploader/build/asset-manifest.json @@ -1,15 +1,15 @@ { "files": { "main.css": "/static/css/main.4ae54ac6.chunk.css", - "main.js": "/static/js/main.7266b749.chunk.js", - "main.js.map": "/static/js/main.7266b749.chunk.js.map", + "main.js": "/static/js/main.ccbe5721.chunk.js", + "main.js.map": "/static/js/main.ccbe5721.chunk.js.map", "runtime~main.js": "/static/js/runtime~main.a8a9905a.js", "runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map", "static/css/2.1eb883ec.chunk.css": "/static/css/2.1eb883ec.chunk.css", - "static/js/2.a41b16cf.chunk.js": "/static/js/2.a41b16cf.chunk.js", - "static/js/2.a41b16cf.chunk.js.map": "/static/js/2.a41b16cf.chunk.js.map", + "static/js/2.6001b07b.chunk.js": "/static/js/2.6001b07b.chunk.js", + "static/js/2.6001b07b.chunk.js.map": "/static/js/2.6001b07b.chunk.js.map", "index.html": "/index.html", - "precache-manifest.a34f6f07da0e4c9969330f1c0db2bbca.js": "/precache-manifest.a34f6f07da0e4c9969330f1c0db2bbca.js", + "precache-manifest.5cead564eb6cd8571ee73903a5f485a0.js": "/precache-manifest.5cead564eb6cd8571ee73903a5f485a0.js", "service-worker.js": "/service-worker.js", "static/css/2.1eb883ec.chunk.css.map": "/static/css/2.1eb883ec.chunk.css.map", "static/css/main.4ae54ac6.chunk.css.map": "/static/css/main.4ae54ac6.chunk.css.map", diff --git a/lambdas/static-asset-uploader/build/index.html b/lambdas/static-asset-uploader/build/index.html index 7c3547f79..6d9568cbc 100644 --- a/lambdas/static-asset-uploader/build/index.html +++ b/lambdas/static-asset-uploader/build/index.html @@ -1 +1 @@ -
=e&&(t=r<0?e-1:e),t}},N.prototype={callFunction:function(e,t){var r=this.functionTable[e];if(void 0===r)throw new Error("Unknown function: "+e+"()");return this._validateArgs(e,t,r._signature),r._func.call(this,t)},_validateArgs:function(e,t,r){var n,i,o,a;if(r[r.length-1].variadic){if(t.lengths&&(s=r,t=i[c]);return t},_functionMinBy:function(e){for(var t,r,n=e[1],i=e[0],o=this.createKeyFunction(n,[a,u]),s=1/0,c=0;c