Skip to content

Instantly share code, notes, and snippets.

View adrianhall's full-sized avatar

Adrian Hall adrianhall

View GitHub Profile
$util.qr($context.args.location.put("owner", $context.identity.username))
$util.qr($context.args.location.put("lastUpdated", $util.time.nowISO8601()))
{
"version": "2017-02-28",
"operation": "PutItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
"typeName": $util.dynamodb.toDynamoDBJson("LOCATION")
},
"attributeValues": $util.dynamodb.toMapValuesJson($context.args.location)
AuthRole:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:custom.api}-auth
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Federated: cognito-identity.amazonaws.com
custom:
# AWS AppSync GraphQL configuration
appSync:
name: ${self:custom.api}
authenticationType: AWS_IAM
logConfig:
loggingRoleArn: { Fn::GetAtt: [ AppSyncLoggingServiceRole, Arn ]}
level: ALL
schema: ./schema.graphql
dataSources:
functions:
dynamodb_stream:
handler: elasticsearch.lambda_handler
name: ${self:custom.api}-dynamodb_stream_handler
description: Stream data from DynamoDB to ElasticSearch
runtime: python3.6
memorySize: 128
role: ElasticSearchStreamingLambdaIAMRole
environment:
ES_ENDPOINT: { Fn::GetAtt: [ ElasticSearchDomain, DomainEndpoint ]}
ElasticSearchStreamingLambdaIAMRole:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:custom.api}-ESStreamingLambdaRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: "lambda.amazonaws.com"
custom:
# The base name of the API for resource generation - can't include dashes
# [a-zA-Z0-9]+ only
api: ${self:provider.stage}RestaurantReviews
# ES Domain, must match [a-z][a-z0-9\-]+
es_domain: ${self:provider.stage}-restaurant-reviews
# The number of instances to launch into the ElasticSearch domain
es_instanceCount: 1
# The type of instance to launch into the ElasticSearch domain
es_instanceType: "t2.small.elasticsearch"
ElasticSearchDomain:
Type: AWS::Elasticsearch::Domain
Properties:
DomainName: ${self:custom.es_domain}
ElasticsearchVersion: "6.2"
ElasticsearchClusterConfig:
ZoneAwarenessEnabled: false
InstanceCount: ${self:custom.es_instanceCount}
InstanceType: ${self:custom.es_instanceType}
EBSOptions:
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.api}
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: typeName
KeyType: RANGE
AttributeDefinitions:
input PagingRequest {
limit: Int
nextToken: String
}
type User {
id: ID!
name: String
locations(paging: PagingRequest): LocationPagingConnection
reviews(paging: PagingRequest): ReviewPagingConnection
type Subscription {
updatedLocation(locationId: ID!): Location
@aws_subscribe(mutations: [ "addReview", "addFavorite" ])
}