Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
service: sls-${self:custom.application}
plugins:
- serverless-python-requirements
- serverless-prune-plugin
custom:
pythonRequirements:
dockerizePip: true
slim: true
noDeploy:
- typing
stage: ${opt:stage, self:custom.defaults.stage}
region: ${opt:region, self:custom.defaults.region}
application: ${env:APPLICATION, self:custom.defaults.application}
logRetentionInDays: ${opt:logretentionindays, env:logretentionindays, self:custom.defaults.logretentionindays}
s3:
websiteBucket: sls-${self:custom.application}-website-${self:custom.stage}
dynamodb:
transportPositionTableName: transportPosition
billingMode: PAY_PER_REQUEST
defaults:
application: tps
stage: dev
region: ap-southeast-2
logretentionindays: 14
prune:
automatic: true
number: 1
provider:
name: aws
runtime: python3.7
endpointType: regional
stage: ${self:custom.stage}
region: ${self:custom.region}
memorySize: 256
timeout: 300
versionFunctions: false
deploymentBucket: sls-${self:custom.application}-deploymentbucket
logRetentionInDays: ${self:custom.logRetentionInDays}
environment:
STAGE: ${self:custom.stage}
REGION: ${self:custom.region}
# define IAM roles
iamRoleStatements:
- Effect: Allow
Action:
- s3:HeadObject
- s3:GetObject
- s3:GetObjectAcl
- s3:PutObject
- s3:PutObjectAcl
- s3:CreateMultiPartUpload
Resource:
- arn:aws:s3:::${self:custom.s3.websiteBucket}/*
- Effect: Allow
Action:
- dynamodb:*
Resource:
- !GetAtt transportPositionTable.Arn
- !Join
- ''
- - !GetAtt transportPositionTable.Arn
- '/index/TripDate-GSI'
# you can add packaging information here
package:
include:
- src/csv/*.csv
exclude:
- __cache__/**
- __pycache__/**
- events/**
- node_modules/**
- 'conf/**/*'
- 'gulp-libs/**/*'
- 'yarn.lock'
- 'package.json'
- '.dotenv'
functions:
tpsFindVehiclePositionsCron:
handler: src.tps_vehiclepos.run
memorySize: 3008
timeout: 900
environment:
BUCKET: ${self:custom.s3.websiteBucket}
TRANSPORTPOSITION_TABLE: ${self:custom.dynamodb.transportPositionTableName}
events:
- schedule:
rate: cron(0/5 * * * ? *)
enabled: true
resources:
Description: Transport Positioning System Resources
Resources:
websiteBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.s3.websiteBucket}
#DynamoDB will be used to store the label that each transport will be given
#The label will be used as the pushpin label on the map.
#DynamoDB will have attributes TripDate, TripId, VehicleId, ExpirationTime(TTL),
#TimeAdded, Latitude, Longitude, PushpinLabel, PushPinLabelDescr
transportPositionTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.dynamodb.transportPositionTableName}
AttributeDefinitions:
- AttributeName: TripDate
AttributeType: S
- AttributeName: VehicleId
AttributeType: S
KeySchema:
- AttributeName: TripDate
KeyType: HASH
- AttributeName: VehicleId
KeyType: RANGE
BillingMode: ${self:custom.dynamodb.billingMode}
GlobalSecondaryIndexes:
- IndexName: TripDate-GSI
KeySchema:
- AttributeName: TripDate
KeyType: HASH
Projection:
ProjectionType: ALL
TimeToLiveSpecification:
AttributeName: ExpirationTime
Enabled: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.