RFC: AppSync abstraction for SAM #3075
Replies: 5 comments 12 replies
-
|
That's a great idea, the template in its actual form is very verbose ... |
Beta Was this translation helpful? Give feedback.
-
|
I'm glad to see the SAM team are looking into providing a simplified syntax for AppSync. I have a number of concerns with the proposal that broadly fall into scalability (large API's) and consistency (does this feel like the rest of SAM or are we doing something different): Scalability
Consistency
Globals:
GraphQLFunction:
CodeS3Location: path/to/{Name}.{RuntimeFileExtension}
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
GraphQLResolver:
RequestMappingTemplateS3Location: path/to/{TypeName}.{FieldName}.request.{RuntimeFileExtension}
ResponseMappingTemplateS3Location: path/to/{TypeName}.{FieldName}.response.{RuntimeFileExtension}
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
You'll notice that only one of my points is to make sure that we can build large API's. The rest are an attempt to make the new Serverless AppSync resources feel like SAM instead of something that's just been bolted on. |
Beta Was this translation helpful? Give feedback.
-
|
How would the new Typescript support fit into this? |
Beta Was this translation helpful? Give feedback.
-
|
We listened and made building a serverless GraphQL API a bit easier with a new abstraction AWS::Serverless::GraphQLApi. https://aws.amazon.com/about-aws/whats-new/2023/06/aws-appsync-abstraction/ |
Beta Was this translation helpful? Give feedback.
-
|
Yes it is available in SAM service and SAM CLI. Sorry you are having trouble. I am not able to replicate your error message. I tested using examples @ssenchenko made, please try these and see if you have the same issue? If you do it is probably an issue with the CLI install, if you do not it is probably a template specific issue
If you use Visual Studio code with the AWS Toolkit plugin (and ensure YAML and not ssm-yaml asl-yaml is the type) it will lint and give you hopefully more detailed errors and contextual properties help ( other editors can use the schema as detailed in #2645 ) Note this discussion thread is closed and we may not notice responses, if you are still having issues please open a new issue. Thanks |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This RFC seeks feedback on a proposal for a new
AWS::Serverless:GraphQLApiresource abstraction for SAM. In this proposal, we outline the challenges SAM customers have authoring AppSync based applications today as well as how a new proposed SAM resource type,AWS::Serverless::GraphQLApi, will simplify the authoring, packaging, and delivery of SAM applications that leverage AppSync.Problem
AppSync, an AWS service for serverless GraphQL solution, is a popular solution for SAM customers to build backend services for web, mobile, and many other types of applications. However, SAM customers have a few challenges when composing their application’s resources in a SAM template.
Ideally, SAM will help reduce the number of CloudFormation resources that must be authored and integrated, the IAM policies needed for resolvers to interact with data sources, and help update AppSync schema and resolver code.
The example below demonstrates the challenge of authoring multiple AppSync resources, a database, and IAM policies to so everything can interact appropriately.
Proposed Solution
Overview
Serverless Application Model (SAM) Transform has been successfully providing higher level abstractions for CFN serverless resources. At the same time, SAM CLI delivers developer tools for code deploy, debugging and testing. SAM philosophy is to concentrate on the most frequent use cases and set properties’ defaults to improve UX for those frequent cases first of all. Following this spirit, SAM abstraction for GraphQL will address following aspects
Serverless::FunctionThe above CFN example will look like following with SAM
GraphQLApiresource, considering that all VTL resolvers are rewritten in JS and project has the following structure:Though each part of SAM
GraphQLApiis described below, here are some notes on major differences between SAM and AppSync resources:Properties and resources which are mapped 1:1 with AppSync
Some properties exactly match those of AppSync resources
Name(of API)TagsXrayEnabledAuthenticationType(Auth.Typein SAM)LambdaAuthorizerConfig(Auth.Configin SAM; additionally, SAM will generate policy to call Lambda Authorizer function)OpenIDConnectConfigAdditionalAuthenticationProvidersInlineCodeorCodeUri(toDefinitionandDefinitionS3LocationofAWS::AppSync::GraphQLSchema)Cache(toAWS::AppSync::ApiCache)Logging is enabled by default and SAM creates LogGroups if none are provided.
DomainNamehas all fields ofAWS::AppSync::DomainNameandAWS::AppSync::DomainNameAssociationis generate by SAM.ApiKeys maps to
AWS::AppSync::ApiKeyand will supportExpiresOnas a date (as opposed to AppSync resource which supports onlydouble)Data Sources
There are 2 natively supported data sources:
DynamoDbandLambda. DataSources are grouped by their type so the structure is flattened and all properties fromConfigare moved one level up to the data source itself.For
DynamoDbthe only required property isTableName. DataSourceNameproperty becomes optional and set Logical ID by default.AwsRegionis also optional and populated by default withAWS::Region(stack region).Role and Policy to access DynamoDb Table is generated by SAM in the same manner as it’s done by Connectors. Default access level will be
ReadandWrite, but it’s possible to choose only one of them.Lambda data source can be also defined in a similar manner which is useful when it should be referenced in an AppSync data source, outside of SAM GraphQLApi resource. See more on that in FAQ.
There is no need to manually create DataSource of type
NONE, SAM generates it. More on that in AppSync Resolvers and Functions sections below.Lambda Resolvers
In addition to having 2 separate resources like AppSync, SAM offers a shortcut to merge Lambda data source and resolver which works with Lambda data source into a single abstraction. The reason for that is that Lambda data source acts as a resolver and allows to remove runtime restrictions which exist for AppSync resolvers.
Permissions to AppSync data source to invoke Lambda functions will be generated by SAM.
Since JS unit resolvers are not supported currently, SAM generates a resolver and a function to perform request/response redirection to/from Lambda.
Pipeline Resolvers and Functions
With introducing JS pipeline resolvers AppSync solved 2 problems which existed before:
SAM
GraphQLApisupports only JS and pipeline resolvers as they are the most convenient and full solution exiting. Only Pipeline resolvers are available at the moment. JS unit resolvers will be supported as soon as AppSync adds them.SAM resolvers are grouped by field type Query, Mutation, Subscription, or any type name the same way, fields are grouped in the GraphQL schema file.
SAM generates inline code to stash all resolver incoming parameters so they are available in the first function and to redirect response from the last function in the pipeline. To override that code, define
CodeUriwith a path to the file with the resolver code or useInlineCodefield.DataSource with type
NONEis generated by SAM if a function or a resolver hasDataSource: None.FAQ
Why SAM
GraphQLApidoesn’t have native support for VTL resolvers? AppSync recommends to use JS resolvers and pipeline functions. VTL is supported by AppSync for backward compatibility.I prefer or need to use VTL. Can I do it with SAM GraphQLApi? Yes. It’s still possible to use AppSync VTL resolvers with SAM GraphQLApi. AppSync resources should be defined separately but they can reference SAM ApiId or DataSourceName from SAM resource. Here is an example:
Can I use SAM
GraphQLApiif I’m working with a data source which is not supported by SAM (ie Relation DB, HttpApi etc)? Yes. An AppSync data source can be define outside of SAMGraphQLApiand then referenced in a resolver or a pipeline function usingDataSourceNameproperty (contrary toDataSourceproperty which is used for a data source defined inside SAM resource).Is it necessary to move all pipeline functions inside SAM
GraphQLApiresource to use them in pipeline resolvers defined inside SAM resource? No. It’s possible to use AppSyncFunctionConfigurationresource. It must be referenced byFunctionIdlike in an AppSync resolver.Beta Was this translation helpful? Give feedback.
All reactions