On console:
$ export AWS_ACCESS_KEY_ID='any_value'
$ export AWS_SECRET_ACCESS_KEY='any_value'
$ export AWS_SERVICE_REGION='us-west-2'
$ export IS_LOCAL=1
$ serverless offline start
If using TypeScript, invoke tsc
to compile and generate dist/ folder (from where serverless will run the code).
To config DynamoDB in JavaScript:
import * as AWS from 'aws-sdk';
AWS.config.update({ region: process.env.AWS_SERVICE_REGION });
let config = { convertEmptyValues: true } as unknown;
if (process.env.IS_LOCAL) {
config = {
region: 'localhost',
endpoint: 'http://localhost:8000',
accessKeyId: 'DEFAULT_ACCESS_KEY', // needed if you don't have aws credentials at all in env
secretAccessKey: 'DEFAULT_SECRET', // needed if you don't have aws credentials at all in env
convertEmptyValues: true
}
};;
export const client = new AWS.DynamoDB.DocumentClient(config);