Anybody know why this is happening? ```is not aut...
# help
f
Anybody know why this is happening?
Copy code
is not authorized to perform: dynamodb:Query on resource
My lambda function cannot query my DynamoDB
m
did you gave permissions?
f
@manitej is it not automatically created by the SST scripts?
m
can i see your api code?
f
@manitej the handler? or the stack?
m
anything is fine, share the stack code
f
Copy code
export function ApiStack(ctx: StackContext) {
  const ddb = use(StorageStack);

  const api = new Api(ctx.stack, "Api", {
    routes: {
      ...customer_routes,
      ...order_routes,
      ...payout_routes,
      ...product_routes,
      ...store_routes,
      ...transaction_routes,
    },
    defaults: {
      function: {
        environment: {
          storesTableName: ddb.storesTable.tableName,
          payoutsTableName: ddb.payoutsTable.tableName,
        },
      },
    },
  });

  ctx.stack.addOutputs({
    ApiEndpoint: api.url,
  });
}
@manitej
m
add the below code in
function: {
permissions: [ddb]
f
Ok! Thank you!
m
Copy code
defaults: {
      function: {
        // Pass in the table name to our API
        environment: {
          ....
        },
        permissions: [ddb],
      },
    }
you need to explicitly give the permissions to resources
f
I changed it to this
Copy code
defaults: {
      function: {
        environment: {
          storesTableName: ddb.storesTable.tableName,
          payoutsTableName: ddb.payoutsTable.tableName,
        },
        permissions: [ddb.storesTable, ddb.payoutsTable],
      },
    },
The code above has an error
@manitej
m
what error @Francis Menguito
f
So I changed it to this
It works now! tysm!
m
awesome 👍