# help

Shubham Sinha

05/19/2022, 6:28 PM
I need help structuring the stacks. I am using go for lamda functions Following this article I created StorageStack to create DynamoDb table and S3 bucket. Now I want to use the table in my functions and for doing that I need to pass table name ( ) how to I get access to the table defined in StorageStack in ApiStack ? Should I move table instantiation to ApiStack itself ?


05/19/2022, 6:30 PM
hey so we're in the process of migrating all our examples to 1.0
but check this out, it documents generally ho wyou share resources across stacks:

Shubham Sinha

05/19/2022, 6:32 PM
@thdxr For every function we have package as main and a main function. This is causing an error


05/19/2022, 6:56 PM
with go each function needs to be in its own folder
we should maybe make that more clear in our starter

Mohiuddin Sumon

05/20/2022, 9:30 AM
@Shubham Sinha have you tried to make one main function and in it just pass them to wherever required

Adrian Schweizer

05/20/2022, 10:16 AM
with regards to the initial question, I'm doing something like this for multiple tables:
Copy code
export 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) => ({
      ["TABLE_NAME_" + key.toUpperCase()]: tables[key].tableName,
   }), {});

   return { bucket, tables, tableNames };
and then in api stack:
Copy code
export function ApiStack({ stack, app }) {
   const { bucket, tables, tableNames } = use(StorageStack);

   const api = new Api(stack, "api", {
      defaults: {
         function: {
            environment: {
and then in lambda I can use table names like this:
Copy code