aquanow-users-lambda
v5.41.1
Published
AWS Lambda Functions
Downloads
3
Readme
AWSLambda
AWS Lambda Functions
Dev
Under root directory, run
npm ci
Make sure your editor support eslint and prettier (maybe you'll need to add extensions for them). VS Code (https://code.visualstudio.com/) is suggested here as the editor.
Configure Visual Studio Code
Install Eslint and Prettier extensions
Update settings to make use of the extensions, and let Prettier auto-format the code based on the eslint config file. More specifically: In the top nav bar of VS Code, click Code -> Preferences -> Settings ->
{}
at the top right coner as shown below.
Update the settings as
{
// Editor
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"window.openFilesInNewWindow": "on",
"window.zoomLevel": 0,
"editor.fontSize": 14,
"files.autoSave": "onFocusChange",
"editor.formatOnSave": true,
// Use eslint config as the rules for prettier
"javascript.format.enable": false, // disable default formatter
"prettier.eslintIntegration": true
}
Then restart the vs code editor, you should see Prettier automatically format your code, whenver you save your file.
Deploy using Serverless
Prerequisites:
####Setup serverless module
First install serverless globally:
npm install -g serverless
####Setup AWS credentials
Edit ~/.aws/credentials
and ~/.aws/config
files under directory. For windows users this is `C:\Users\USERNAME.aws'
credentials
file:
[aquaNow-PROD]
aws_access_key_id=...
aws_secret_access_key=...
config
file - configure profile name and cloudformation stack region
[aquaNow-PROD]
region=us-east-1
Start to deploy
When deploying the project, a stage variable is used to specify which environment (AWS Account) will the lambdas (as well as other infrastructures) be deployed to. Currently the available stage variables include: PROD
, DEV
.
Deploy the entire project:
sls deploy --stage PROD
Update a function - this is useful when you want to update and test a single lambda function:
sls deploy --stage PROD --function orderHistory
Miscellaneous
Create API Key for a user
const request = require("request");
const executeAPIUrl = 'https://execute.aquanow.io'; // Adjust your url accordingly
const options = {
method: 'POST',
url: `${executeAPIUrl}/apiKey`,
headers:
{
'cache-control': 'no-cache',
'Content-Type': 'application/json'
},
body: {
userId: 'fuzionadmin', // required | username
customerId: 'aquanow', // optional
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Run scripts in script folder
Make sure you have correct aws credentials configured on your terminal. You can check aws credentials using aws configure
npm run script scripts/addRfqExchange.js