- Nodejs v6.5.0 or later
- Serverless CLI v1.9.0 or later (
npm i -g serverless
) - Choose your computer provider (AWS on my case) Give serverless access to our cloud provider account so that it can create and manage resources on our behalf. For this we need to create a policy with the appropriate permissions and a user to assign those.
- AWS Services -> IAM -> Policies -> Create Policy -> JSON -> Copy & Paste the following gist: https://gist.github.com/ServerlessBot/7618156b8671840a539f405dea2704c8 (apply changes needed)
- Add name and description.
- AWS Services -> IAM -> Users -> Create User
- Add name and enable programmatic access
- Link permissions to the previously created policy
- Download the credentials csv
sls config credentials --provider aws --key key --secret secret --profile profile
dev:
DYNAMODB_LOCAL_PORT: 9200
CRYPTO_SECRET_KEY: CRYPTO_SECRET_KEY
JWT_SECRET: JWT_SECRET
PROFILE: PROFILE
require('crypto').randomBytes(20, (err, buffer) => {
if (!err) {
const token = buffer.toString('hex')
console.log(token)
}
})
sls deploy
sls remove
Note: when using DeletionPolicy: Retain
on the db tables as on this case, after remove, we need to clean up the tables also. Otherwise we would see an error when trying to deploy again.
sls logs --function functionName
sls dynamodb install
sls dynamodb start
sls offline