This example provides a structured approach to deploying a Serverless GraphQL API using AWS Serverless Application Model (SAM), leveraging Nested Stacks for modularity.
Project Structure: Modular Stacks The core idea is to break down the infrastructure into specialized, manageable units using SAM’s Nested Stacks. This separation enhances clarity, reusability, and maintainability.
The Root Template acts as the orchestrator, defining the dependencies between the smaller stacks:
RolesStack (stacks/roles.yaml): Creates the necessary IAM Roles for Lambda execution and for AppSync to invoke the Lambda function. GraphQLStack (stacks/graphql.yaml): Provisions the AWS AppSync GraphQL API, including the API itself, the API Key, and the Schema definition (which is assumed to be uploaded to an S3 location). FunctionsStack (stacks/functions.yaml): Deploys the Lambda function, the AppSync Data Source, and the Resolvers query.graphql the schema definition can also be split into smaller files (types, queries, and mutations). These fragments are then merged into a single final schema file (schema.graphql). The best thing about this design is that everything is organized and independent. Each group of functions or resources is in its own box (stack).
...