Shubham Sinha
05/19/2022, 6:28 PMthdxr
05/19/2022, 6:30 PMthdxr
05/19/2022, 6:30 PMShubham Sinha
05/19/2022, 6:32 PMShubham Sinha
05/19/2022, 6:54 PMthdxr
05/19/2022, 6:56 PMthdxr
05/19/2022, 6:56 PMMohiuddin Sumon
05/20/2022, 9:30 AMAdrian Schweizer
05/20/2022, 10:16 AMexport const StorageStack = ({ stack }) => {
const bucket = new Bucket(stack, "Uploads", {
// bucket config
});
const tables = {
organisations: new Table(stack, "Organisations", {
// table config
}),
participations: new Table(stack, "Participations", {
// table config
}),
// more tables
};
// Collect table names to later add them to process environment for lambda functions
const tableNames = Object.keys(tables).reduce((tableNames, key) => ({
...tableNames,
["TABLE_NAME_" + key.toUpperCase()]: tables[key].tableName,
}), {});
return { bucket, tables, tableNames };
}
and then in api stack:
export function ApiStack({ stack, app }) {
const { bucket, tables, tableNames } = use(StorageStack);
const api = new Api(stack, "api", {
defaults: {
function: {
environment: {
...tableNames,
},
},
},
and then in lambda I can use table names like this:
process.env.TABLE_NAME_PARTICIPATIONS