Contents

AWS AppSync on AWS SAM

Image credit to AWS News Blog - https://aws.amazon.com/blogs/aws/new-aws-sam-local-beta-build-and-test-serverless-applications-locally/

Introduction

Developers creating serverless applications now have the capability to construct AWS Serverless Application Model (SAM)-powered applications with the latest AWS::Serverless::GraphQLApi resource abstraction, enabling seamless integration with AppSync. AWS AppSync, a managed service facilitating the development of scalable APIs connecting applications to data through a GraphQL endpoint, further simplifies the process.

Why use AWS Serverless Application Model (SAM)

The AWS Serverless Application Model (SAM) is a framework, available as open-source, designed for the construction of serverless applications. It offers a concise syntax for expressing functions, APIs, databases, and event source mappings. By utilizing just a few lines of code per resource, you can define and model your desired application using YAML. During the deployment process, SAM automatically transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling accelerated development of serverless applications.

To initiate the creation of SAM-based applications, the recommended tool is the AWS SAM CLI. The SAM CLI provides an execution environment similar to Lambda, allowing you to locally build, test, and debug applications defined through SAM templates or utilizing the AWS Cloud Development Kit (CDK). Additionally, the SAM CLI offers the capability to deploy your applications to AWS and create secure continuous integration and deployment (CI/CD) pipelines adhering to best practices, seamlessly integrating with both native AWS and third-party CI/CD systems.

Find more about these tools using the links below

Creating an AWS::Serverless::GraphQLApi

The YAML example below provides you the syntax, extracted from the documentation, that you can use to create your resource.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
LogicalId:
  Type: AWS::Serverless::GraphQLApi
  Properties:
    ApiKeys: ApiKeys
    Auth: Auth
    Cache: AWS::AppSync::ApiCache
    CustomDomainName: AWS::AppSync::DomainName
    DataSources: DataSource
    Functions: Function
    Logging: LogConfig
    Name: String
    Resolvers: Resolver
    SchemaInline: String
    SchemaUri: String
    Tags:
    - Tag
    XrayEnabled: Boolean

In the syntax, I want to highlight two important properties, which are DataSources, that allows you to configure the data sources to use (e.g. DynamoDb) and the Functions, that allows you to configure the functions in GraphQL APIs to perform the operations you need


If you want to explore the properties and access some examples of using this syntax to create the resource, acccess this link .

Have a great day!