Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify Gen2 Data Construct does not expose tables or cfnTables #2137

Closed
2 tasks done
dbanksdesign opened this issue Dec 14, 2023 · 17 comments
Closed
2 tasks done

Amplify Gen2 Data Construct does not expose tables or cfnTables #2137

dbanksdesign opened this issue Dec 14, 2023 · 17 comments
Assignees
Labels
bug Something isn't working Gen 2

Comments

@dbanksdesign
Copy link

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 to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

Based on https://docs.amplify.aws/gen2/build-a-backend/data/override-resources/ I should be able to access the tables the data construct creates, but those objects are empty

import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource.js';
import { data } from './data/resource.js';

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

const dataResources = backend.resources.data.resources;

console.log(dataResources.tables); // {}
console.log(dataResources.cfnResources.cfnTables); // {}

Object.values(dataResources.cfnResources.cfnTables).forEach((table) => {
  console.log(table);
});

Expected behavior

I should have access to them like the docs says

Reproduction steps

Follow https://docs.amplify.aws/gen2/start/ to create a gen2 app, then write the code in https://docs.amplify.aws/gen2/build-a-backend/data/override-resources/ it will fail because dataResources.tables["Todo"] is undefined because the tables object is empty.

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@AnilMaktala AnilMaktala added Gen 2 bug Something isn't working and removed pending-triage labels Dec 15, 2023
@AnilMaktala
Copy link
Member

Hey @dbanksdesign, Thank you for bringing this to our attention. We've managed to replicate the issue, so we're categorizing it as a bug for the team to investigate further.

image

@palpatim
Copy link
Member

The issue here is that the Data construct's table creation strategy is to use the Amplify-provisioned iterative tables, rather than the CloudFormation-managed default. That means the resource shows up under dataResources.amplifyDynamoDbTables["Todo"] rather than dataResources.tables["Todo"]. That object exposes a different set of properties than the Table, so to accomplish the example, you'd do:

Object.values(dataResources.amplifyDynamoDbTables).forEach((table) => {
  table.pointInTimeRecoveryEnabled = false;
});

@AaronZyLee will be working to find the right way to update our docs to reflect this change.

@bebbo-zz
Copy link

bebbo-zz commented Jan 3, 2024

Would I be able to get an ARN or StreamARN via amplifyDynamoDbTables? If not, I assume it is more than just a documentation problem, right?

@m-arrieta-r
Copy link

I did a test directly with CDK, and I didn't encounter the problem (https://gist.github.com/marnutux/f22b06dc8398babfa1f04c61daf36b0b#file-amplify-stack-example-ts-L30). I only have the issue when using the abstraction defineData, so I'm not sure if it should be reported as an issue at https://github.com/aws-amplify/amplify-backend.

@AnilMaktala AnilMaktala removed the documentation Improvements or additions to documentation label Jan 23, 2024
@jrobertshawe
Copy link

Hi there. Via the same method, would I be able to add a Global Index. I did not see a way to do this via the Data resource model

@AnilMaktala
Copy link
Member

Hey, We are working on it and it will be released as part of GA.

@AnilMaktala
Copy link
Member

Hey @jrobertshawe, We have completed the work for backend and currently working on the client side library. We will let you know as soon as it is released.

@AnilMaktala
Copy link
Member

This issue has been fixed in release:

@aws-amplify/backend": "^0.13.0-beta.6
@aws-amplify/backend-cli": "^0.12.0-beta.6

@pavinthan
Copy link

@AnilMaktala still same, here are my amplify backend versions

@aws-amplify/backend": "^0.13.0-beta.17
@aws-amplify/backend-cli": "^0.12.0-beta.19

@dpilch dpilch reopened this Apr 17, 2024
@renebrandel
Copy link
Contributor

@pavinthan - you should be able to access the resources under cfnResources.cfnAmplifyTables the reason is we're exposing them via a custom CDK resource in order to allow for multiple GSI updates.

Copy link

github-actions bot commented May 3, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@dwil618
Copy link

dwil618 commented May 20, 2024

Hi @renebrandel

I have been following a trail of issues and discord threads all pointing to this issue. As far as I can tell the tables and cfnTables still don't work. Unless I am missing something?

I would like to be able to add a DynamoEventSource for my lambda as described in the documentation

Also looking at other challenges like adding Tags to my tables. Do you have any advice here?

@renebrandel
Copy link
Contributor

Hey. You should be able to use cfnAmplifyTables, which provide the same interface. The reasons is to address some of the workflow problems (like updating multiple GSIs in a single request) requires us to use a custom Amplify DDB table resource.

@renebrandel
Copy link
Contributor

The L2 reference (.tables) should work as is though.

@dwil618
Copy link

dwil618 commented May 20, 2024

Thanks for the speedy response and clarification! First part was my misunderstanding of the different interfaces.

I still have some problem with adding tags though. I see no error when using the below code, but it doesn't add any tags in the generated template/deployed resource.
Tags.of(backend.data.resources.tables.Task).add('test', '123');

@paulochagass
Copy link

Thanks for the speedy response and clarification! First part was my misunderstanding of the different interfaces.

I still have some problem with adding tags though. I see no error when using the below code, but it doesn't add any tags in the generated template/deployed resource. Tags.of(backend.data.resources.tables.Task).add('test', '123');

Same problem here.

@MyNameIsTakenOMG
Copy link

MyNameIsTakenOMG commented Sep 13, 2024

Same here. And in my case, I was trying to override some settings for my gsi, but in the end I had to use custom resource to help me with that.

Also I believe this could potentially an issue when we have multiple GSIs to create or configure, because if we configure our GSIs by following the amplify gen2 doc, then by default all those GSIs will be created with a ProjectionType of ALL, which is not practical in reality, because in most cases, we only want the necessary fields projected into our GSI tables, right?

Again, I understand the amplify devs have good reasons to design backend.data this way, but I still hope in the near future we could have more flexibility to configure the underlying dynamodb table, for example, in my case, maybe we could have an option to configure GSIs for our tables through backend.data.resources.cfnResources.amplifyDynamoDbTables

@AaronZyLee AaronZyLee removed their assignment Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gen 2
Projects
None yet
Development

No branches or pull requests