├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── amplify.json ├── amplify ├── backend │ ├── backend-config.json │ └── auth │ │ └── amplifyreactapp17ff568b │ │ ├── parameters.json │ │ └── amplifyreactapp17ff568b-cloudformation-template.yml ├── .config │ └── project-config.json └── team-provider-info.json ├── src ├── setupTests.js ├── App.test.js ├── index.css ├── index.js ├── App.js ├── App.css ├── logo.svg └── serviceWorker.js ├── .gitignore ├── package.json └── README.md /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamWSoftware/amplify-react-tutorial-project/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamWSoftware/amplify-react-tutorial-project/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamWSoftware/amplify-react-tutorial-project/HEAD/public/logo512.png -------------------------------------------------------------------------------- /amplify.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": 3 | { 4 | "graphqltransformer": 5 | { 6 | "transformerversion": 5 7 | }, 8 | "keytransformer": 9 | { 10 | "defaultquery": true 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /amplify/backend/backend-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "auth": { 3 | "amplifyreactapp17ff568b": { 4 | "service": "Cognito", 5 | "providerPlugin": "awscloudformation", 6 | "dependsOn": [], 7 | "customAuth": false 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /amplify/.config/project-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "amplifyreactapp", 3 | "version": "3.0", 4 | "frontend": "javascript", 5 | "javascript": { 6 | "framework": "react", 7 | "config": { 8 | "SourceDir": "src", 9 | "DistributionDir": "build", 10 | "BuildCommand": "npm run-script build", 11 | "StartCommand": "npm run-script start" 12 | } 13 | }, 14 | "providers": [ 15 | "awscloudformation" 16 | ] 17 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister(); 18 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import logo from './logo.svg'; 3 | import './App.css'; 4 | import Amplify from 'aws-amplify'; 5 | import awsconfig from './aws-exports'; 6 | import { AmplifySignOut, withAuthenticator } from '@aws-amplify/ui-react'; 7 | 8 | Amplify.configure(awsconfig); 9 | 10 | function App() { 11 | return ( 12 |
13 |
14 | 15 |

My App Content

16 |
17 |
18 | ); 19 | } 20 | 21 | export default withAuthenticator(App); 22 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .vscode 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | #amplify 27 | amplify/\#current-cloud-backend 28 | amplify/.config/local-* 29 | amplify/mock-data 30 | amplify/backend/amplify-meta.json 31 | amplify/backend/awscloudformation 32 | build/ 33 | dist/ 34 | node_modules/ 35 | aws-exports.js 36 | awsconfiguration.json 37 | amplifyconfiguration.json 38 | amplify-build-config.json 39 | amplify-gradle-config.json 40 | amplifytools.xcconfig -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amplify-react-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@aws-amplify/ui-react": "^0.2.14", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "aws-amplify": "^3.0.23", 11 | "react": "^16.13.1", 12 | "react-dom": "^16.13.1", 13 | "react-scripts": "3.4.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /amplify/team-provider-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "dev": { 3 | "awscloudformation": { 4 | "AuthRoleName": "amplify-amplifyreactapp-dev-205704-authRole", 5 | "UnauthRoleArn": "arn:aws:iam::455632876623:role/amplify-amplifyreactapp-dev-205704-unauthRole", 6 | "AuthRoleArn": "arn:aws:iam::455632876623:role/amplify-amplifyreactapp-dev-205704-authRole", 7 | "Region": "eu-west-2", 8 | "DeploymentBucketName": "amplify-amplifyreactapp-dev-205704-deployment", 9 | "UnauthRoleName": "amplify-amplifyreactapp-dev-205704-unauthRole", 10 | "StackName": "amplify-amplifyreactapp-dev-205704", 11 | "StackId": "arn:aws:cloudformation:eu-west-2:455632876623:stack/amplify-amplifyreactapp-dev-205704/80336aa0-da7a-11ea-befa-020a477b9a30", 12 | "AmplifyAppId": "d2hifp93qt8q49" 13 | }, 14 | "categories": { 15 | "auth": { 16 | "amplifyreactapp17ff568b": {} 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /amplify/backend/auth/amplifyreactapp17ff568b/parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "identityPoolName": "amplifyreactapp17ff568b_identitypool_17ff568b", 3 | "allowUnauthenticatedIdentities": false, 4 | "resourceNameTruncated": "amplif17ff568b", 5 | "userPoolName": "amplifyreactapp17ff568b_userpool_17ff568b", 6 | "autoVerifiedAttributes": [ 7 | "email" 8 | ], 9 | "mfaConfiguration": "OFF", 10 | "mfaTypes": [ 11 | "SMS Text Message" 12 | ], 13 | "smsAuthenticationMessage": "Your authentication code is {####}", 14 | "smsVerificationMessage": "Your verification code is {####}", 15 | "emailVerificationSubject": "Your verification code", 16 | "emailVerificationMessage": "Your verification code is {####}", 17 | "defaultPasswordPolicy": false, 18 | "passwordPolicyMinLength": 8, 19 | "passwordPolicyCharacters": [], 20 | "requiredAttributes": [ 21 | "email" 22 | ], 23 | "userpoolClientGenerateSecret": true, 24 | "userpoolClientRefreshTokenValidity": 30, 25 | "userpoolClientWriteAttributes": [ 26 | "email" 27 | ], 28 | "userpoolClientReadAttributes": [ 29 | "email" 30 | ], 31 | "userpoolClientLambdaRole": "amplif17ff568b_userpoolclient_lambda_role", 32 | "userpoolClientSetAttributes": false, 33 | "sharedId": "17ff568b", 34 | "resourceName": "amplifyreactapp17ff568b", 35 | "authSelections": "identityPoolAndUserPool", 36 | "authRoleArn": { 37 | "Fn::GetAtt": [ 38 | "AuthRole", 39 | "Arn" 40 | ] 41 | }, 42 | "unauthRoleArn": { 43 | "Fn::GetAtt": [ 44 | "UnauthRole", 45 | "Arn" 46 | ] 47 | }, 48 | "useDefault": "default", 49 | "usernameAttributes": [ 50 | "email" 51 | ], 52 | "userPoolGroupList": [], 53 | "dependsOn": [] 54 | } -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `yarn build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /amplify/backend/auth/amplifyreactapp17ff568b/amplifyreactapp17ff568b-cloudformation-template.yml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | 3 | Parameters: 4 | env: 5 | Type: String 6 | authRoleArn: 7 | Type: String 8 | unauthRoleArn: 9 | Type: String 10 | 11 | 12 | 13 | 14 | identityPoolName: 15 | Type: String 16 | 17 | allowUnauthenticatedIdentities: 18 | Type: String 19 | 20 | resourceNameTruncated: 21 | Type: String 22 | 23 | userPoolName: 24 | Type: String 25 | 26 | autoVerifiedAttributes: 27 | Type: CommaDelimitedList 28 | 29 | mfaConfiguration: 30 | Type: String 31 | 32 | mfaTypes: 33 | Type: CommaDelimitedList 34 | 35 | smsAuthenticationMessage: 36 | Type: String 37 | 38 | smsVerificationMessage: 39 | Type: String 40 | 41 | emailVerificationSubject: 42 | Type: String 43 | 44 | emailVerificationMessage: 45 | Type: String 46 | 47 | defaultPasswordPolicy: 48 | Type: String 49 | 50 | passwordPolicyMinLength: 51 | Type: Number 52 | 53 | passwordPolicyCharacters: 54 | Type: CommaDelimitedList 55 | 56 | requiredAttributes: 57 | Type: CommaDelimitedList 58 | 59 | userpoolClientGenerateSecret: 60 | Type: String 61 | 62 | userpoolClientRefreshTokenValidity: 63 | Type: Number 64 | 65 | userpoolClientWriteAttributes: 66 | Type: CommaDelimitedList 67 | 68 | userpoolClientReadAttributes: 69 | Type: CommaDelimitedList 70 | 71 | userpoolClientLambdaRole: 72 | Type: String 73 | 74 | userpoolClientSetAttributes: 75 | Type: String 76 | 77 | sharedId: 78 | Type: String 79 | 80 | resourceName: 81 | Type: String 82 | 83 | authSelections: 84 | Type: String 85 | 86 | useDefault: 87 | Type: String 88 | 89 | usernameAttributes: 90 | Type: CommaDelimitedList 91 | 92 | userPoolGroupList: 93 | Type: CommaDelimitedList 94 | 95 | dependsOn: 96 | Type: CommaDelimitedList 97 | 98 | Conditions: 99 | ShouldNotCreateEnvResources: !Equals [ !Ref env, NONE ] 100 | 101 | Resources: 102 | 103 | 104 | # BEGIN SNS ROLE RESOURCE 105 | SNSRole: 106 | # Created to allow the UserPool SMS Config to publish via the Simple Notification Service during MFA Process 107 | Type: AWS::IAM::Role 108 | Properties: 109 | RoleName: !If [ShouldNotCreateEnvResources, 'amplif17ff568b_sns-role', !Join ['',[ 'sns', '17ff568b', !Select [3, !Split ['-', !Ref 'AWS::StackName']], '-', !Ref env]]] 110 | AssumeRolePolicyDocument: 111 | Version: "2012-10-17" 112 | Statement: 113 | - Sid: "" 114 | Effect: "Allow" 115 | Principal: 116 | Service: "cognito-idp.amazonaws.com" 117 | Action: 118 | - "sts:AssumeRole" 119 | Condition: 120 | StringEquals: 121 | sts:ExternalId: amplif17ff568b_role_external_id 122 | Policies: 123 | - 124 | PolicyName: amplif17ff568b-sns-policy 125 | PolicyDocument: 126 | Version: "2012-10-17" 127 | Statement: 128 | - 129 | Effect: "Allow" 130 | Action: 131 | - "sns:Publish" 132 | Resource: "*" 133 | # BEGIN USER POOL RESOURCES 134 | UserPool: 135 | # Created upon user selection 136 | # Depends on SNS Role for Arn if MFA is enabled 137 | Type: AWS::Cognito::UserPool 138 | UpdateReplacePolicy: Retain 139 | Properties: 140 | UserPoolName: !If [ShouldNotCreateEnvResources, !Ref userPoolName, !Join ['',[!Ref userPoolName, '-', !Ref env]]] 141 | 142 | Schema: 143 | 144 | - 145 | Name: email 146 | Required: true 147 | Mutable: true 148 | 149 | 150 | 151 | 152 | AutoVerifiedAttributes: !Ref autoVerifiedAttributes 153 | 154 | 155 | EmailVerificationMessage: !Ref emailVerificationMessage 156 | EmailVerificationSubject: !Ref emailVerificationSubject 157 | 158 | Policies: 159 | PasswordPolicy: 160 | MinimumLength: !Ref passwordPolicyMinLength 161 | RequireLowercase: false 162 | RequireNumbers: false 163 | RequireSymbols: false 164 | RequireUppercase: false 165 | 166 | UsernameAttributes: !Ref usernameAttributes 167 | 168 | MfaConfiguration: !Ref mfaConfiguration 169 | SmsVerificationMessage: !Ref smsVerificationMessage 170 | SmsConfiguration: 171 | SnsCallerArn: !GetAtt SNSRole.Arn 172 | ExternalId: amplif17ff568b_role_external_id 173 | 174 | 175 | UserPoolClientWeb: 176 | # Created provide application access to user pool 177 | # Depends on UserPool for ID reference 178 | Type: "AWS::Cognito::UserPoolClient" 179 | Properties: 180 | ClientName: amplif17ff568b_app_clientWeb 181 | 182 | RefreshTokenValidity: !Ref userpoolClientRefreshTokenValidity 183 | UserPoolId: !Ref UserPool 184 | DependsOn: UserPool 185 | UserPoolClient: 186 | # Created provide application access to user pool 187 | # Depends on UserPool for ID reference 188 | Type: "AWS::Cognito::UserPoolClient" 189 | Properties: 190 | ClientName: amplif17ff568b_app_client 191 | 192 | GenerateSecret: !Ref userpoolClientGenerateSecret 193 | RefreshTokenValidity: !Ref userpoolClientRefreshTokenValidity 194 | UserPoolId: !Ref UserPool 195 | DependsOn: UserPool 196 | # BEGIN USER POOL LAMBDA RESOURCES 197 | UserPoolClientRole: 198 | # Created to execute Lambda which gets userpool app client config values 199 | Type: 'AWS::IAM::Role' 200 | Properties: 201 | RoleName: !If [ShouldNotCreateEnvResources, !Ref userpoolClientLambdaRole, !Join ['',['upClientLambdaRole', '17ff568b', !Select [3, !Split ['-', !Ref 'AWS::StackName']], '-', !Ref env]]] 202 | AssumeRolePolicyDocument: 203 | Version: '2012-10-17' 204 | Statement: 205 | - Effect: Allow 206 | Principal: 207 | Service: 208 | - lambda.amazonaws.com 209 | Action: 210 | - 'sts:AssumeRole' 211 | DependsOn: UserPoolClient 212 | UserPoolClientLambda: 213 | # Lambda which gets userpool app client config values 214 | # Depends on UserPool for id 215 | # Depends on UserPoolClientRole for role ARN 216 | Type: 'AWS::Lambda::Function' 217 | Properties: 218 | Code: 219 | ZipFile: !Join 220 | - |+ 221 | - - 'const response = require(''cfn-response'');' 222 | - 'const aws = require(''aws-sdk'');' 223 | - 'const identity = new aws.CognitoIdentityServiceProvider();' 224 | - 'exports.handler = (event, context, callback) => {' 225 | - ' if (event.RequestType == ''Delete'') { ' 226 | - ' response.send(event, context, response.SUCCESS, {})' 227 | - ' }' 228 | - ' if (event.RequestType == ''Update'' || event.RequestType == ''Create'') {' 229 | - ' const params = {' 230 | - ' ClientId: event.ResourceProperties.clientId,' 231 | - ' UserPoolId: event.ResourceProperties.userpoolId' 232 | - ' };' 233 | - ' identity.describeUserPoolClient(params).promise()' 234 | - ' .then((res) => {' 235 | - ' response.send(event, context, response.SUCCESS, {''appSecret'': res.UserPoolClient.ClientSecret});' 236 | - ' })' 237 | - ' .catch((err) => {' 238 | - ' response.send(event, context, response.FAILED, {err});' 239 | - ' });' 240 | - ' }' 241 | - '};' 242 | Handler: index.handler 243 | Runtime: nodejs10.x 244 | Timeout: '300' 245 | Role: !GetAtt 246 | - UserPoolClientRole 247 | - Arn 248 | DependsOn: UserPoolClientRole 249 | UserPoolClientLambdaPolicy: 250 | # Sets userpool policy for the role that executes the Userpool Client Lambda 251 | # Depends on UserPool for Arn 252 | # Marked as depending on UserPoolClientRole for easier to understand CFN sequencing 253 | Type: 'AWS::IAM::Policy' 254 | Properties: 255 | PolicyName: amplif17ff568b_userpoolclient_lambda_iam_policy 256 | Roles: 257 | - !Ref UserPoolClientRole 258 | PolicyDocument: 259 | Version: '2012-10-17' 260 | Statement: 261 | - Effect: Allow 262 | Action: 263 | - 'cognito-idp:DescribeUserPoolClient' 264 | Resource: !GetAtt UserPool.Arn 265 | DependsOn: UserPoolClientLambda 266 | UserPoolClientLogPolicy: 267 | # Sets log policy for the role that executes the Userpool Client Lambda 268 | # Depends on UserPool for Arn 269 | # Marked as depending on UserPoolClientLambdaPolicy for easier to understand CFN sequencing 270 | Type: 'AWS::IAM::Policy' 271 | Properties: 272 | PolicyName: amplif17ff568b_userpoolclient_lambda_log_policy 273 | Roles: 274 | - !Ref UserPoolClientRole 275 | PolicyDocument: 276 | Version: 2012-10-17 277 | Statement: 278 | - Effect: Allow 279 | Action: 280 | - 'logs:CreateLogGroup' 281 | - 'logs:CreateLogStream' 282 | - 'logs:PutLogEvents' 283 | Resource: !Sub 284 | - arn:aws:logs:${region}:${account}:log-group:/aws/lambda/${lambda}:log-stream:* 285 | - { region: !Ref "AWS::Region", account: !Ref "AWS::AccountId", lambda: !Ref UserPoolClientLambda} 286 | DependsOn: UserPoolClientLambdaPolicy 287 | UserPoolClientInputs: 288 | # Values passed to Userpool client Lambda 289 | # Depends on UserPool for Id 290 | # Depends on UserPoolClient for Id 291 | # Marked as depending on UserPoolClientLambdaPolicy for easier to understand CFN sequencing 292 | Type: 'Custom::LambdaCallout' 293 | Properties: 294 | ServiceToken: !GetAtt UserPoolClientLambda.Arn 295 | clientId: !Ref UserPoolClient 296 | userpoolId: !Ref UserPool 297 | DependsOn: UserPoolClientLogPolicy 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | # BEGIN IDENTITY POOL RESOURCES 306 | 307 | 308 | IdentityPool: 309 | # Always created 310 | Type: AWS::Cognito::IdentityPool 311 | Properties: 312 | IdentityPoolName: !If [ShouldNotCreateEnvResources, 'amplifyreactapp17ff568b_identitypool_17ff568b', !Join ['',['amplifyreactapp17ff568b_identitypool_17ff568b', '__', !Ref env]]] 313 | 314 | CognitoIdentityProviders: 315 | - ClientId: !Ref UserPoolClient 316 | ProviderName: !Sub 317 | - cognito-idp.${region}.amazonaws.com/${client} 318 | - { region: !Ref "AWS::Region", client: !Ref UserPool} 319 | - ClientId: !Ref UserPoolClientWeb 320 | ProviderName: !Sub 321 | - cognito-idp.${region}.amazonaws.com/${client} 322 | - { region: !Ref "AWS::Region", client: !Ref UserPool} 323 | 324 | AllowUnauthenticatedIdentities: !Ref allowUnauthenticatedIdentities 325 | 326 | 327 | DependsOn: UserPoolClientInputs 328 | 329 | 330 | IdentityPoolRoleMap: 331 | # Created to map Auth and Unauth roles to the identity pool 332 | # Depends on Identity Pool for ID ref 333 | Type: AWS::Cognito::IdentityPoolRoleAttachment 334 | Properties: 335 | IdentityPoolId: !Ref IdentityPool 336 | Roles: 337 | unauthenticated: !Ref unauthRoleArn 338 | authenticated: !Ref authRoleArn 339 | DependsOn: IdentityPool 340 | 341 | 342 | Outputs : 343 | 344 | IdentityPoolId: 345 | Value: !Ref 'IdentityPool' 346 | Description: Id for the identity pool 347 | IdentityPoolName: 348 | Value: !GetAtt IdentityPool.Name 349 | 350 | 351 | 352 | 353 | UserPoolId: 354 | Value: !Ref 'UserPool' 355 | Description: Id for the user pool 356 | UserPoolName: 357 | Value: !Ref userPoolName 358 | AppClientIDWeb: 359 | Value: !Ref 'UserPoolClientWeb' 360 | Description: The user pool app client id for web 361 | AppClientID: 362 | Value: !Ref 'UserPoolClient' 363 | Description: The user pool app client id 364 | AppClientSecret: 365 | Value: !GetAtt UserPoolClientInputs.appSecret 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | --------------------------------------------------------------------------------