Skip to content

Instantly share code, notes, and snippets.

@yonahforst
Last active December 26, 2018 08:47
Show Gist options
  • Save yonahforst/c522c0d675ba827d64e943cf45470520 to your computer and use it in GitHub Desktop.
Save yonahforst/c522c0d675ba827d64e943cf45470520 to your computer and use it in GitHub Desktop.
Getting started with `serverless-cqrs` -  part 3 - serverless.yml
service: myService
## define some static variables
custom:
writeModelTableName: commitsByEntityIdAndVersion
writeModelIndexName: indexByEntityNameAndCommitId
readModelDomainName: readmodel
provider:
name: aws
runtime: nodejs8.10
## make these values available in process.env
environment:
WRITE_MODEL_TABLENAME: ${self:custom.writeModelTableName}
WRITE_MODEL_INDEXNAME: ${self:custom.writeModelIndexName}
ELASTIC_READ_MODEL_ENDPOINT:
Fn::GetAtt:
- ReadModelProjections
- DomainEndpoint
## allow our lambda functions to access to following resources
iamRoleStatements:
- Effect: Allow
Action:
- "dynamodb:*"
Resource: "arn:aws:dynamodb:*:*:table/${self:custom.writeModelTableName}*"
- Effect: "Allow"
Action:
- "es:*"
Resource:
- "arn:aws:es:*:*:domain/${self:custom.readModelDomainName}/*"
- Effect: "Allow"
Action:
- "es:ESHttpGet"
Resource:
- "*"
## create the following API Gateway endpoints and connect them to our app
functions:
router:
handler: index.handler
events:
- http: POST
- http: GET {id}
- http: PUT {id}/{index}
- http: DELETE {id}
resources:
Resources:
## create the dynamodb table for storing events
EventStoreTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:custom.writeModelTableName}
AttributeDefinitions:
- AttributeName: entityId
AttributeType: S
- AttributeName: version
AttributeType: N
- AttributeName: entityName
AttributeType: S
- AttributeName: commitId
AttributeType: S
KeySchema:
- AttributeName: entityId
KeyType: HASH
- AttributeName: version
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
GlobalSecondaryIndexes:
- IndexName: ${self:custom.writeModelIndexName}
KeySchema:
- AttributeName: entityName
KeyType: HASH
- AttributeName: commitId
KeyType: RANGE
Projection:
ProjectionType: INCLUDE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
## create an ElasticSearch instance for storing read model projections
ReadModelProjections:
Type: 'AWS::Elasticsearch::Domain'
Properties:
DomainName: ${self:custom.readModelDomainName}
ElasticsearchVersion: 6.2
EBSOptions:
EBSEnabled: true
VolumeSize: 10
VolumeType: gp2
ElasticsearchClusterConfig:
InstanceType: t2.small.elasticsearch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment