UnlyEd/serverless-plugin-dynamodb-backups

View on GitHub
examples/serverless-example/serverless.yml

Summary

Maintainability
Test Coverage
# For full config options, check the docs:
#    docs.serverless.com

service: example-dynamodbAutoBackups

frameworkVersion: "2"
configValidationMode: error

plugins:
  - '@unly/serverless-plugin-dynamodb-backups' # Must be first, even before "serverless-webpack", see https://github.com/UnlyEd/serverless-plugin-dynamodb-backups
  - serverless-webpack # Must be second, see https://github.com/99xt/serverless-dynamodb-local#using-with-serverless-offline-and-serverless-webpack-plugin
  - serverless-offline # See https://github.com/dherault/serverless-offline

custom:
  dynamodbAutoBackups: # @unly/serverless-plugin-dynamodb-backups configuration (see README for more)
    backupRate: rate(1 minute) # Set to 1mn in the example to see the result quickly
    source: src/backups.handler
    name: ${self:custom.name} # Using the service name as a base name may be a good practice (but it doesn't work at the time, due to a bug on our side)
    backupRemovalEnabled: true
    backupRetentionDays: 1 # Created backups will be removed the next day
  name: example-dynamodbAutoBackups
  serverless-offline:
    port: 3000
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
    packager: yarn

provider:
  name: aws
  runtime: nodejs14.x
  lambdaHashingVersion: 20201221
  stage: development # TODO You may want to change this
  region: eu-west-1 # TODO You may want to change this
  profile: sandbox # TODO You need to either remove this or use your own profile
  environment:
    TABLE_NAME: Book # We specify the table name so we can check its backups list using the dedicated endpoint /listBackups

functions:
  listBackups: # Endpoint example to see the list of all backups that have been made
    handler: src/listBackups.handler
    events:
      - http:
          method: GET
          path: /listBackups

resources:
  Resources:
    BookTable: # Create dynamodb table on aws for testing
      Type: AWS::DynamoDB::Table # see https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
      Properties:
        TableName: Book
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1