From d7c5f704cae2589cd31c190ceb87e61a2852984b Mon Sep 17 00:00:00 2001 From: Michael de Wal Date: Sat, 24 Aug 2024 09:16:00 +0900 Subject: [PATCH] Add api_id to the client output file amplify_outputs.json. This allows for the backend to import the json and use raw DBB queries on tables using the api_id for example: import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, TransactWriteCommand } from "@aws-sdk/lib-dynamodb"; import config from '../../../../amplify_outputs.json'; const client = new DynamoDBClient({}); const docClient = DynamoDBDocumentClient.from(client); const createTableName = (name: string) => { return `${name}-${config.data.api_id}-NONE`; } export const handler = async (event: any) => { const { userId, amount } = event.arguments; const transactItems = [ // Update UserProfile { Update: { TableName: createTableName('UserProfile'), Key: { id: userId }, UpdateExpression: 'ADD currentPoints :pointsToAdd', ExpressionAttributeValues: { ':pointsToAdd': amount } } } ]; try { const results = await docClient.send(new TransactWriteCommand({ TransactItems: transactItems })); console.log(results) return results['$metadata'] } catch (error) { console.error('Error:', error); throw new Error('Failed to process the transaction'); } }; --- .../client-config-contributor/client_config_contributor_v1.ts | 1 + .../client-config/src/client-config-schema/client_config_v1.1.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/client-config/src/client-config-contributor/client_config_contributor_v1.ts b/packages/client-config/src/client-config-contributor/client_config_contributor_v1.ts index 4f4c2e8eec..653127fe33 100644 --- a/packages/client-config/src/client-config-contributor/client_config_contributor_v1.ts +++ b/packages/client-config/src/client-config-contributor/client_config_contributor_v1.ts @@ -220,6 +220,7 @@ export class DataClientConfigContributor implements ClientConfigContributor { config.data = { url: graphqlOutput.payload.awsAppsyncApiEndpoint, aws_region: graphqlOutput.payload.awsAppsyncRegion, + api_id: graphqlOutput.payload.awsAppsyncApiId, api_key: graphqlOutput.payload.awsAppsyncApiKey, default_authorization_type: graphqlOutput.payload.awsAppsyncAuthenticationType, diff --git a/packages/client-config/src/client-config-schema/client_config_v1.1.ts b/packages/client-config/src/client-config-schema/client_config_v1.1.ts index 0bce94d1a4..9cbd8cd1f4 100644 --- a/packages/client-config/src/client-config-schema/client_config_v1.1.ts +++ b/packages/client-config/src/client-config-schema/client_config_v1.1.ts @@ -163,6 +163,7 @@ export interface AWSAmplifyBackendOutputs { model_introspection?: { [k: string]: unknown; }; + api_id?: string; api_key?: string; default_authorization_type: AwsAppsyncAuthorizationType; authorization_types: AwsAppsyncAuthorizationType[];