-
Notifications
You must be signed in to change notification settings - Fork 79
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
Get ApiId or Table Name in custom handler #2708
Comments
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂 |
Hey @godrimcom, Thank you for bringing this up. Could you please clarify if you have already reviewed the relevant documentation on this topic? |
Hi @godrimcom At the moment there is no way, at least that I'm aware of, to access and pass the table name to a resolver without incurring a "circular dependency" error. You may have to hard code the table name and pass it as an environment variable. ex: backend.data.resources.cfnResources.cfnGraphqlApi.environmentVariables = {
TODO_TABLE:
// replace with your own table name
`Todo-md4n36jl7za7xi4mie3cs3wyey-NONE`,
}; in the resolver you'd access environment variables from the context: import { util } from "@aws-appsync/utils";
export const request = (ctx) => {
const todos = [];
ctx.args.todos.forEach(({id}) => {
todo.push(util.dynamodb.toMapValues({ id }));
});
return {
operation: "BatchGetItem",
tables: {
[ctx.env.TODO_TABLE]: {
keys: todos,
},
},
};
};
export const response = (ctx) => {
return ctx.result.data[ctx.env.TODO_TABLE];
}; we are working on a way to make the DDB tables accessible. UPDATE: You can also compute the name of the table because it will be in the format I'm not sure what determines |
Hi @chrisbonifacio , just checking that you know you can access the table name from the data resources.
|
@andrew-clark-dev Hey, that works! Didn't know you could do that. Thanks! backend.sharpFunction.resources.cfnResources.cfnFunction.environment = {
variables: {
TODO_TABLE: backend.data.resources.tables["Todo"].tableName,
},
}; |
This issue is now closed. Comments on closed issues are hard for our team to see. |
That does not work for me, i'm still getting a circular dependency error. |
I think this happens because maybe you are using dynamoDB streams on that function? which causes a circular dependency. I am having the same problem, and need to find the solution. |
I am having the same problem getting a circular dependency , did you solve it? |
I have circular dependency too! |
Environment information
Description
I'm using amplify gen 2 and I added a custom handler in my schema:
this is my handler:
I just want to do a BatchDeleteItem operation. This should be a basic operation, please help
The text was updated successfully, but these errors were encountered: