-
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
Accessing graphql api via custom lambda function #2996
Comments
Hi @jayarerita can you confirm that the environment variables are not being added to the Lambda in the AWS Console? Can you also share the schema? |
@chrisbonifacio I can confirm that the function does not have any of these environment variables in the lambda function in the console. The data.resource schema does not seem consequential. I can share a simple example though.... import { type ClientSchema, a, defineData } from "@aws-amplify/backend";
import { postConfirmation } from "../auth/post-confirmation/resource";
const schema = a
.schema({
TableA: a
.model({
id: a.id().required(),
title: a.string(),
description: a.string(),
owner: a.string(),
})
.authorization((allow) =>[
allow.owner(),
]),
UserProfile: a.model({
name: a.string(),
email: a.string().required(),
role: a.enum(["user", "admin"]),
profileOwner: a.string(),
id: a.id().required(),
})
.authorization((allow) => [
allow.ownerDefinedIn("profileOwner"),
]),
})
.authorization((allow) => ([
allow.resource(postConfirmation),
]))
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "apiKey",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
}); |
Hi @jayarerita apologies for the delay. I was not able to reproduce the issue but I'm curious if you tried adding the graphql url as an environment variable through CDK as you did with the table name. That could serve as a workaround until we figure out why allow.resource didn't work in this instance. This might be due to the lambda not having been created by This part of the AWS docs may be helpful: It seems like a workaround would be to provide the permissions via the addToRolePolicy function and access the IAM credentials using a function like Also, if you haven't already, please upgrade to the latest versions of you can also upgrade the npm update @aws-amplify/data-schema |
Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you. Thank you! |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Amplify CLI Version
Amplify Gen 2 ampx v1.0.4
Question
I have a lambda function which is listening to dynamodb events for one of my tables. Below is a basic example of how my table and function are defined in my backend.ts file.
In the docs you are instructed to add your defined lambda functions as
allow.resource(functionWithDataAccess)
on the data schema.I assume this adds permissions, which I can do via cdk, but also provides some key env variables like
env.<amplifyData>_GRAPHQL_ENDPOINT
andenv.AWS_ACCESS_KEY_ID
which seem to be needed to configure the amplify data client and perform operations on the graphql api.It looks like I might be able to access the endpoint url via
backend.data.graphqlUrl
, but I am not sure where I can get access to the authorization values.The text was updated successfully, but these errors were encountered: