serverless-stack-demo-ext-api icon indicating copy to clipboard operation
serverless-stack-demo-ext-api copied to clipboard

stack-demo-ext-api out of sync with stack-demo-api

Open biganth opened this issue 5 years ago • 2 comments

I recently updated my api app to use the updated logic in the libs folder of the demo api but now I'm transitioning my app to the ext format to deploy on seed but the ext app hasn't been updated with the new logic.

Demo API Version

import AWS from "aws-sdk";
const client = new AWS.DynamoDB.DocumentClient();

export default {
  get   : (params) => client.get(params).promise(),
  put   : (params) => client.put(params).promise(),
  query : (params) => client.query(params).promise(),
  update: (params) => client.update(params).promise(),
  delete: (params) => client.delete(params).promise(),
};

EXT version

import AWS from "./aws-sdk";
import config from "../config";

const dynamoDb = new AWS.DynamoDB.DocumentClient();

export function call(action, params) {
  // Parameterize table names with stage name
  return dynamoDb[action]({
    ...params,
    TableName: `${config.resourcesStage}-${params.TableName}`
  }).promise();
}

Looks like we just need to spread the params into the table name stage.

get: (params) => client.get({
    ...params,
    TableName: `${config.resourcesStage}-${params.TableName}`
  }).promise()

biganth avatar May 31 '20 06:05 biganth

Found the cleaner implementation in the guide: https://serverless-stack.com/chapters/manage-environment-related-config.html

...

export default {
  get: (params) => client.get(updateTableName(params)).promise(),
  query: (params) => client.query(updateTableName(params)).promise(),
  put: (params) => client.put(updateTableName(params)).promise(),
  update: (params) => client.update(updateTableName(params)).promise(),
  delete: (params) => client.delete(updateTableName(params)).promise(),
};

function updateTableName(params) {
  return {
    ...params,
    TableName: `${config.resourcesStage}-${params.TableName}`,
  };
}

biganth avatar May 31 '20 15:05 biganth

Hmm the ext version is definitely lighter on these details. Is there something we should add to the guide to fix this?

jayair avatar Jun 13 '20 23:06 jayair