Skip to content

Instantly share code, notes, and snippets.

@onedal
Created November 29, 2019 04:15
Show Gist options
  • Save onedal/099343d4c32d62c5612f5c7442d13136 to your computer and use it in GitHub Desktop.
Save onedal/099343d4c32d62c5612f5c7442d13136 to your computer and use it in GitHub Desktop.
SAM with graphql example
AWSTemplateFormatVersion: 2010-09-09
Description: GraphQL Example Stack
Resources:
DeploymentMarkerTagIAPO39:
Type: AWS::CloudFormation::WaitConditionHandle
Graphql:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
AuthenticationType: API_KEY
LogConfig:
CloudWatchLogsRoleArn:
Fn::GetAtt:
- GraphqlLogsRole
- Arn
FieldLogLevel: ERROR
Name: Graphql
Type: AWS::AppSync::GraphQLApi
GraphqlLogsRole:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
AssumeRolePolicyDocument:
Statement:
Action: sts:AssumeRole
Effect: Allow
Principal:
Service: appsync.amazonaws.com
Version: 2012-10-17
Policies:
- PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
- Fn::Sub: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/appsync/apis/*
- Fn::Sub: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/appsync/apis/*:log-stream:*
Version: 2012-10-17
PolicyName: Log
RoleName:
Fn::Sub: ${AWS::StackName}-Graphql-logs
Type: AWS::IAM::Role
GraphqlMutationaddPostResolver:
DependsOn:
- GraphqlSchema
- DeploymentMarkerTagIAPO39
Properties:
ApiId:
Fn::GetAtt:
- Graphql
- ApiId
DataSourceName:
Fn::GetAtt:
- GraphqlToLambdaResolverDataSource
- Name
FieldName: addPost
RequestMappingTemplateS3Location: ../../template/Graphql/Mutation-addPost-request.vm
ResponseMappingTemplateS3Location: ../../template/Graphql/Mutation-addPost-response.vm
TypeName: Mutation
Type: AWS::AppSync::Resolver
GraphqlQueryallPostsResolver:
DependsOn:
- GraphqlSchema
- DeploymentMarkerTagIAPO39
Properties:
ApiId:
Fn::GetAtt:
- Graphql
- ApiId
DataSourceName:
Fn::GetAtt:
- GraphqlToLambdaResolverDataSource
- Name
FieldName: allPosts
RequestMappingTemplateS3Location: ../../template/Graphql/Query-allPosts-request.vm
ResponseMappingTemplateS3Location: ../../template/Graphql/Query-allPosts-response.vm
TypeName: Query
Type: AWS::AppSync::Resolver
GraphqlQuerygetPostResolver:
DependsOn:
- GraphqlSchema
- DeploymentMarkerTagIAPO39
Properties:
ApiId:
Fn::GetAtt:
- Graphql
- ApiId
DataSourceName:
Fn::GetAtt:
- GraphqlToLambdaResolverDataSource
- Name
FieldName: getPost
RequestMappingTemplateS3Location: ../../template/Graphql/Query-getPost-request.vm
ResponseMappingTemplateS3Location: ../../template/Graphql/Query-getPost-response.vm
TypeName: Query
Type: AWS::AppSync::GraphQLSchema
GraphqlSchema:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
ApiId:
Fn::GetAtt:
- Graphql
- ApiId
DefinitionS3Location: ../../template/Graphql/schema.graphql
Type: AWS::AppSync::GraphQLSchema
GraphqlToLambdaResolverAccessRole:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
AssumeRolePolicyDocument:
Statement:
Action: sts:AssumeRole
Effect: Allow
Principal:
Service: appsync.amazonaws.com
Version: 2012-10-17
Policies:
- PolicyDocument:
Statement:
- Action: lambda:InvokeFunction
Effect: Allow
Resource:
Fn::GetAtt:
- LambdaResolver
- Arn
Version: 2012-10-17
PolicyName: Access
RoleName:
Fn::Sub: ${AWS::StackName}-Graphql-to-LambdaRes
Type: AWS::IAM::Role
GraphqlToLambdaResolverDataSource:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
ApiId:
Fn::GetAtt:
- Graphql
- ApiId
LambdaConfig:
LambdaFunctionArn:
Fn::GetAtt:
- LambdaResolver
- Arn
Name: LambdaResolver
ServiceRoleArn:
Fn::GetAtt:
- GraphqlToLambdaResolverAccessRole
- Arn
Type: AWS_LAMBDA
Type: AWS::AppSync::DataSource
LambdaResolver:
DependsOn: DeploymentMarkerTagIAPO39
Properties:
CodeUri: LambdaResolver
FunctionName:
Fn::Sub: ${AWS::StackName}-LambdaResolver
Handler: index.handler
MemorySize: 3008
Policies:
- AWSXrayWriteOnlyAccess
Runtime: nodejs8.10
Timeout: 30
Tracing: Active
Type: AWS::Serverless::Function
Transform: AWS::Serverless-2016-10-31
@onedal
Copy link
Author

onedal commented Nov 29, 2019

$tree .aws-sam -L 2
.aws-sam
└── build
    ├── LambdaResolver
    └── template.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment