Skip to content

Instantly share code, notes, and snippets.

@digitalbase
Created April 23, 2020 19:27
Show Gist options
  • Select an option

  • Save digitalbase/49414ec30d297a13650db70ba811d9e3 to your computer and use it in GitHub Desktop.

Select an option

Save digitalbase/49414ec30d297a13650db70ba811d9e3 to your computer and use it in GitHub Desktop.
service: segment-attribution
plugins:
- serverless-offline
custom:
tableIdentify: 'segment-event-identify-${self:provider.stage}'
tablePage: 'segment-event-page-${self:provider.stage}'
tableAttribution: 'segment-event-attribution-${self:provider.stage}'
tableUserMapping: 'segment-event-user-map-${self:provider.stage}'
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: eu-west-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:ListStreams
Resource:
- { "Fn::GetAtt": ["SegmentIdentifiesDynamoDBTable", "Arn" ] }
- { "Fn::GetAtt": ["SegmentPageDynamoDBTable", "Arn" ] }
- { "Fn::GetAtt": ["SegmentAttributionDynamoDBTable", "Arn" ] }
- { "Fn::GetAtt": ["SegmentUserMappingDynamoDBTable", "Arn" ] }
environment:
IDENTIFY_TABLE: ${self:custom.tableIdentify}
PAGE_TABLE: ${self:custom.tablePage}
ATTRIBUTION_TABLE: ${self:custom.tableAttribution}
USER_MAP_TABLE: ${self:custom.tableUserMapping}
functions:
- ${file(src/handlers/api/api.serverless.yml)}
- ${file(src/handlers/process.serverless.yml)}
- ${file(src/handlers/segment.serverless.yml)}
resources:
Resources:
SegmentIdentifiesDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
StreamSpecification:
StreamViewType: NEW_IMAGE
AttributeDefinitions:
- AttributeName: messageId
AttributeType: S
KeySchema:
- AttributeName: messageId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.tableIdentify}
SegmentPageDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
StreamSpecification:
StreamViewType: NEW_IMAGE
AttributeDefinitions:
- AttributeName: messageId
AttributeType: S
KeySchema:
- AttributeName: messageId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.tablePage}
SegmentAttributionDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: anonymousId
AttributeType: S
- AttributeName: eventId
AttributeType: S
KeySchema:
- AttributeName: anonymousId
KeyType: HASH
- AttributeName: eventId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.tableAttribution}
SegmentUserMappingDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: anonymousId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: anonymousId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.tableUserMapping}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment