amplify-backend
amplify-backend copied to clipboard
Duplicate identifier 'AMPLIFY_DATA_GRAPHQL_ENDPOINT' for allowing a function access to SQL And GraphQL schemas
Environment information
System:
OS: macOS 14.5
CPU: (14) arm64 Apple M3 Max
Memory: 129.25 MB / 36.00 GB
Shell: /bin/zsh
Binaries:
Node: 18.18.0 - ~/.asdf/installs/nodejs/18.18.0/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/18.18.0/bin/yarn
npm: 9.8.1 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: undefined - undefined
NPM Packages:
@aws-amplify/auth-construct: Not Found
@aws-amplify/backend: Not Found
@aws-amplify/backend-auth: Not Found
@aws-amplify/backend-cli: Not Found
@aws-amplify/backend-data: Not Found
@aws-amplify/backend-deployer: Not Found
@aws-amplify/backend-function: Not Found
@aws-amplify/backend-output-schemas: Not Found
@aws-amplify/backend-output-storage: Not Found
@aws-amplify/backend-secret: Not Found
@aws-amplify/backend-storage: Not Found
@aws-amplify/cli-core: Not Found
@aws-amplify/client-config: Not Found
@aws-amplify/deployed-backend-client: Not Found
@aws-amplify/form-generator: Not Found
@aws-amplify/model-generator: Not Found
@aws-amplify/platform-core: Not Found
@aws-amplify/plugin-types: Not Found
@aws-amplify/sandbox: Not Found
@aws-amplify/schema-generator: Not Found
aws-amplify: Not Found
aws-cdk: Not Found
aws-cdk-lib: Not Found
typescript: 5.6.2
AWS environment variables:
AWS_STS_REGIONAL_ENDPOINTS = regional
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables
Describe the bug
The npx ampx sandbox
command outputs duplicate environment variables when granting access for a function to both the generated SQL schema and GraphQL schema.
Here's the error output:
TypeScript validation check failed.
$ /Users/.../Documents/Projects/Tabbi/TabbiApp/node_modules/.bin/tsc --noEmit --skipLibCheck --project amplify
.amplify/generated/env/migrate-lambda.ts(86,3): error TS2300: Duplicate identifier 'AMPLIFY_DATA_GRAPHQL_ENDPOINT'.
.amplify/generated/env/migrate-lambda.ts(87,3): error TS2300: Duplicate identifier 'AMPLIFY_DATA_GRAPHQL_ENDPOINT'.
Inside my .amplify/generated/env/my-lambda.ts
:
/** Amplify backend environment variables available at runtime, this includes environment variables defined in `defineFunction` and by cross resource mechanisms */
type AmplifyBackendEnvVars = {
AMPLIFY_DATA_GRAPHQL_ENDPOINT: string;
AMPLIFY_DATA_GRAPHQL_ENDPOINT: string;
};
Reproduction steps
I'm writing a function that needs to access the SQL schema and GraphQL schema, see the allow.resource(myLambda).to(["query"]),
lines, which apparently leads to the CLI creating two AMPLIFY_DATA_GRAPHQL_ENDPOINT
variables:
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
import { schema as generatedSqlSchema } from './schema.sql';
import { myLambda } from '../functions/my-lambda/resource';
const sqlSchema = generatedSqlSchema.setAuthorization((models) => [
models.users
.authorization(allow => [
allow.guest().to(["read"])
]),
])
.authorization(allow => [
allow.resource(myLambda).to(["query"]),
])
const schema = a.schema({
User: a.model({
email: a.email(),
// phone: a.phone(),
owners: a.string().array(),
}).authorization((allow => [
allow.owner(),
allow.ownersDefinedIn("owners")
]))
})
.authorization(allow => [
allow.resource(myLambda).to(["query"]),
])
const combinedSchema = a.combine([schema, sqlSchema]);
export type Schema = ClientSchema<typeof combinedSchema>;
export const data = defineData({
schema: combinedSchema,
});