A starter project that makes creating a deployable AWS Serverless project extremely easy.
git clone https://github.com/hardyscc/aws-nestjs-starter.git <Your_Project_Name>
cd <Your_Project_Name>
npm install
After that find and replace aws-nestjs-starter
to your project name on the following files:
- package.json
- serverless.yml
- .env
-
Login to your AWS account and go to the Identity & Access Management (IAM) page.
-
Click on Users and then Add user. Enter a name in the first field to remind you this User is related to the Serverless Framework, like
serverless-admin
. Enable Programmatic access by clicking the checkbox. Click Next to go through to the Permissions page. Click on Attach existing policies directly. Search for and select AdministratorAccess then click Next: Review. Check to make sure everything looks good and click Create user. -
View and copy the API Key & Secret to a temporary place. You'll need it in the next step.
Install AWS CLI
- Windows:
choco install awscli
- MacOS:
brew install awscli
Config AWS CLI
$ aws configure
AWS Access Key ID [****************TKYQ]:
AWS Secret Access Key [****************yNO2]:
Default region name [us-east-1]:
Default output format [None]:
Please enter your AWS Access Key ID, AWS Secret Access Key and Default region name
# deploy to AWS
$ npm run deploy
# download dynamodb local into .dynamodb folder
$ npm run ddb:install
# start dynamodb local
$ npm run ddb:start
# start serverless-offline server
$ npm run sls:offline
# start serverless-offline server and connect to online dynamodb
$ npm run sls:online
# start dynamodb local
$ npm run ddb:start
# start local nestjs server
$ npm start
# start local nestjs server in watch mode
$ npm run start:watch
# start local nestjs server and connect to online dynamodb
$ npm run start:online
# re-generate the resources/dynamodb.yml from schemas
$ npm run genres
# run unit test
$ npm test
# run unit test with coverage
$ npm run test:cov
# start dynamodb local
$ npm run ddb:start
# run unit test with coverage
$ npm run test:e2e
- offline: http://localhost:3000/dev/graphql
- local: http://localhost:3000/graphql
- AWS: https://<your_aws_deployment_id>.execute-api.<your_aws_region>.amazonaws.com/dev/graphql
mutation {
createNotification(
input: { targetId: "device1", userId: "user1", content: "Hello World" }
) {
id
}
}
query {
notificationByUserId(userId: "user1") {
id
targetId
userId
content
createAt
}
}
query {
notificationByTargetId(targetId: "device1") {
id
targetId
userId
content
createAt
}
}
mutation {
updateNotification(
id: "1ca7726e-0af8-4ff1-8ef1-4eae97377162"
input: { status: Deleted }
) {
id
targetId
userId
content
createAt
}
}
Please remove
/dev
from path if test using local nestjs mode
curl -X POST 'http://localhost:3000/dev/notification' \
-H 'Content-Type: application/json' \
--data-raw '{ "targetId": "device1", "userId": "user1", "content": "Hello" }'
curl -X GET 'http://localhost:3000/dev/notification?targetId=device1'
curl -X GET 'http://localhost:3000/dev/notification?userId=user1'
curl -X PATCH 'http://localhost:3000/dev/notification/a30f7101-2434-4443-87fa-493c9d9d3358' \
-H 'Content-Type: application/json' \
--data-raw '{ "status": "Deleted" }'
- Author - Hardys
- Twitter - @hardyscchk