npm install -g @aws-amplify/cli
npm init private
amplify init
? Enter a name for the project tenant
? Enter a name for the environment develop
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using none
? Source Directory Path: src
? Distribution Directory Path: dist
? Build Command: npm run-script build
? Start Command: npm run-script start
amplify add auth
Do you want to use the default authentication and security configuration? Manual configuration
Select the authentication/authorization services that you want to use: User Sign-Up, Sign-In, connected with AWS IAM controls (Enables per-user Storage features for images or other content, Analytic
s, and more)
Please provide a friendly name for your resource that will be used to label this category in the project:
Please enter a name for your identity pool.
Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM) No
Do you want to enable 3rd party authentication providers in your identity pool? No
Please provide a name for your user pool:
Warning: you will not be able to edit these selections.
How do you want users to be able to sign in? Email
Do you want to add User Pool Groups? Yes
? Provide a name for your user pool group: ADMIN
? Do you want to add another User Pool Group No
✔ Sort the user pool groups in order of preference · ADMIN
Do you want to add an admin queries API? No
Multifactor authentication (MFA) user login options: OFF
Email based user registration/forgot password: Enabled (Requires per-user email entry at registration)
Please specify an email verification subject: Your verification code
Please specify an email verification message: Your verification code is {####}
Do you want to override the default password policy for this User Pool? No
Warning: you will not be able to edit these selections.
What attributes are required for signing up? Email
Specify the app's refresh token expiration period (in days): 30
Do you want to specify the user attributes this app can read and write? No
Do you want to enable any of the following capabilities?
Do you want to use an OAuth flow? No
? Do you want to configure Lambda Triggers for Cognito? No
amplify push
amplify add api
? Please select from one of the below mentioned services: GraphQL
? Provide API name: tenant
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Do you want to configure advanced settings for the GraphQL API Yes, I want to make some additional changes.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API IAM
? Configure conflict detection? No
? Do you have an annotated GraphQL schema? No
? Do you want a guided schema creation? Yes
? What best describes your project: Single object with fields (e.g., “Todo” with ID, name, description)
? Do you want to edit the schema now? No
Change the graphql to: schema.graphql
FOllow the instructions here: https://medium.com/@vdelacou/how-to-use-typescript-with-aws-amplify-function-d3e271b11d01
npm init private
npm install aws-lambda aws-sdk
npm install --save-dev typescript @types/node @types/aws-lambda [email protected] eslint-plugin-flowtype@3 @typescript-eslint/[email protected] eslint-config-airbnb-base@latest eslint eslint-plugin-import @typescript-eslint/[email protected] eslint-config-airbnb-typescript prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-jsx-a11y eslint-plugin-react [email protected]
curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/eeb8931e510218dac1464d3cd592722c/raw/b689f79c9dea03accb4327b06a16df99448f37f7/tsconfig.json
curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/d6a880059777451a913acd962b8e43a8/raw/.eslintrc.json
curl -o .eslintignore https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.eslintignore
Add the function
amplify add function
? Provide a friendly name for your resource to be used as a label for this category in the project: manageUser
? Provide the AWS Lambda function name: manageUser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to update permissions granted to this Lambda function to perform on other resources in your project? Yes
? Select the category auth, storage
? Auth has 2 resources in this project. Select the one you would like your Lambda to access
? Select the operations you want to permit for create, read, update, delete
? Storage has 3 resources in this project. Select the one you would like your Lambda to access User:@model(appsync)
? Select the operations you want to permit for User:@model(appsync) create, read, update, delete
Copy the function in ts
folder below manageUser.ts
amplify add function
? Provide a friendly name for your resource to be used as a label for this category in the project: getCognitoUser
? Provide the AWS Lambda function name: getCognitoUser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function? Yes
? Select the category auth
? Auth has 2 resources in this project. Select the one you would like your Lambda to access tenant6729c4446729c444
? Select the operations you want to permit for tenant6729c4446729c444 create, read, update, delete
than add in index.ts the getCognitoUser.ts
amplify add function
? Provide a friendly name for your resource to be used as a label for this category in the project: preTokenGeneration
? Provide the AWS Lambda function name: preTokenGeneration
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function?? Yes
? Select the category storage
? Storage has 3 resources in this project. Select the one you would like your Lambda to access User:@model(appsync)
? Select the operations you want to permit for User:@model(appsync) create, read, update, delete
Copy the function in ts
folder below preTokenGeneration.ts
add to root package.json
"scripts": {
"amplify:getCognitoUser": "cd amplify/backend/function/getCognitoUser/ts && npm install && npm run tsc && cd -",
"amplify:manageUser": "cd amplify/backend/function/manageUser/ts && npm install && npm run tsc && cd -",
"amplify:preTokenGeneration": "cd amplify/backend/function/preTokenGeneration/ts && npm install && npm run tsc && cd - "
}
Then amplify push
And then amplify add storage
go to amplify console and choose in policies that only admin can create account
choose in trigger the pretoken function