#✅ - Unable to access the created Dynamo DB tables from data

16 messages · Page 1 of 1 (latest)

plush osprey
#

const backend = defineBackend({
auth,
data
});

console.log(backend.data.resources.tables)

tables is undefined!

dusk bridge
#

Here is the sample to use the data.resources

#

const backend = defineBackend({
auth,
data,
});

const dataResources = backend.resources.data.resources;

dataResources.amplifyDynamoDbTables["Todo"].provisionedThroughput = {
readCapacityUnits: 5,
writeCapacityUnits: 5,
};
Object.values(dataResources.amplifyDynamoDbTables).forEach((table) => {
table.pointInTimeRecoveryEnabled = false;
console.log(table);
});

plush osprey
#

Thank you for the answer! In my case I would like to access the DynamoDB table directly in a lambda function, so I need the generated table name!

warped gulch
#

hey there is currently a github issue open for this
https://github.com/aws-amplify/amplify-category-api/issues/2163
https://github.com/aws-amplify/amplify-category-api/issues/2137

for the table names you may need to utilize a workaround that i could get working but i would suggest testing this in your sandbox
https://github.com/aws-amplify/amplify-category-api/issues/2163#issuecomment-1874354570

GitHub

How did you install the Amplify CLI? No response If applicable, what version of Node.js are you using? No response Amplify CLI Version Gen2 What operating system are you using? mac Did you make any...

GitHub

How did you install the Amplify CLI? npm If applicable, what version of Node.js are you using? 20 Amplify CLI Version gen 2 What operating system are you using? mac Did you make any manual changes ...

slender dragonBOT
#

✅ - Unable to access the created Dynamo DB tables from data

#

Marked as solved.

lavish hatch
warped gulch
lavish hatch
warped gulch
#

yes, for a quick test i set this to a cfn stack output. do note the table name locally would be cfn token if you try to console log it but get resolved on deployment by cfn

const dataResource = backend.data.resources;

new cdk.CfnOutput(backend.data, "dfwddqw", {
  value: dataResource.tables["Todo"].tableName,
  description: "The name of the table",
});

lavish hatch
# warped gulch yes, for a quick test i set this to a cfn stack output. do note the table name l...

Thank you so much for your help here. I have 1 last question do you know why I would be getting a circular dependency here? ```import { defineBackend } from "@aws-amplify/backend";
import * as iam from "aws-cdk-lib/aws-iam";
import { auth } from "./auth/resource";
import { data } from "./data/resource";
import { preSignUp } from "./auth/pre-signup/resource";
import { getUsersByEmailOrPhoneFunction } from "./data/getUsersByEmailOrPhone/resource";
import { Table } from "aws-cdk-lib/aws-dynamodb";
import { Function } from "aws-cdk-lib/aws-lambda";

/**

const getUsersByEmailOrPhoneLambda = backend.getUsersByEmailOrPhoneFunction
.resources.lambda as Function;
getUsersByEmailOrPhoneLambda.addToRolePolicy(
new iam.PolicyStatement({
actions: ["dynamodb:Query"],
resources: ["*"],
})
);

const table = backend.data.resources.tables["UserProfile"] as Table;

getUsersByEmailOrPhoneLambda.addEnvironment(
"USER_PROFILE_TABLE_NAME",
table.tableName
);

backend.data.resources.tables["UserProfile"].grantReadData(
getUsersByEmailOrPhoneLambda
);```

#

I get it when I try this line getUsersByEmailOrPhoneLambda.addEnvironment( "USER_PROFILE_TABLE_NAME", table.tableName );

warped gulch
#

ah thanks for the info, did run into this. but noticed you may be able to get away with creating a custom query with a Lambda function and provide the access to the model from the API.
https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/
something as follows

UserProfile: a.model().authorization(allow => [allow.resource(getUserByEmail).to(["read"]))
getUserByEmail: a.query().returns(a.ref("UserProfile")).handler(a.handler.function(getUserByEmail))
lavish hatch
lavish hatch