Description
This sample pattern demonstrates how to build a secure, generative AI-powered GraphQL API. It shows how to authenticate users with Amazon Cognito, use AWS AppSync to define the GraphQL interface, and then process requests by invoking an Amazon Bedrock foundation model via an AWS Lambda resolver.
The core of this pattern allows authenticated users to send a prompt through an AppSync mutation. This mutation triggers a Node.js AWS Lambda function, which acts as the resolver. The Lambda function, utilizing the AWS SDK for JavaScript (v3), then sends the prompt to a configured Amazon Bedrock model (defaulting to Anthropic Claude 3 Sonnet). The model's response is then relayed back through AppSync to the end-user. Key aspects include secure authentication, scalable GraphQL endpoint, and direct integration with powerful generative AI models.
This pattern deploys an Amazon Cognito User Pool and User Pool Client, an AWS AppSync GraphQL API, an AWS Lambda function (Node.js 20.x runtime), and the necessary IAM roles and permissions for these services to interact securely. The entire infrastructure is provisioned using the AWS Cloud Development Kit (CDK).
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.