Skip to content

Instantly share code, notes, and snippets.

@kmkale
Last active September 29, 2023 11:16
Show Gist options
  • Save kmkale/ae4d9e7dec346664d258d5dc3fd86625 to your computer and use it in GitHub Desktop.
Save kmkale/ae4d9e7dec346664d258d5dc3fd86625 to your computer and use it in GitHub Desktop.
Get Accounts Lambda Stub
/* getAccounts.js
This lambda returns a stubbed response for CDR Get Accounts API
https://consumerdatastandardsaustralia.github.io/standards/#get-accounts
*/
exports.handler = async (event, context) => {
const response = {
statusCode: 200,
body: JSON.stringify({
data: {
accounts: [
{
accountId: 'string',
creationDate: 'string',
displayName: 'string',
nickname: 'string',
openStatus: 'OPEN',
isOwned: true,
maskedNumber: 'string',
productCategory: 'TRANS_AND_SAVINGS_ACCOUNTS',
productName: 'string',
},
],
},
links: {
self: 'string',
first: 'string',
prev: 'string',
next: 'string',
last: 'string',
},
meta: {
totalRecords: 1,
totalPages: 1,
},
}),
};
return response;
};
@Core-Bore
Copy link

Core-Bore commented Sep 29, 2023

If anyone copies this into a lambda with Node.js 18.x. You might get internal server error and Cloudwatch will show:
2023-09-29T09:22:19.531Z undefined ERROR Uncaught Exception { "errorType": "ReferenceError", "errorMessage": "exports is not defined in ES module scope", "stack": [ "ReferenceError: exports is not defined in ES module scope", " at file:///var/task/index.mjs:1:1", " at ModuleJob.run (node:internal/modules/esm/module_job:194:25)" ] }

But its an easy fix. Just change:
exports.handler = async (event, context) => {
to
export const handler = async (event, context) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment