Skip to content

w4rlock/serverless-cloudflare-dns

Repository files navigation

CloudFlare

serverless npm version npm downloads Donate

Installation

npm i -E serverless-cloudflare-dns

Features

- Auth with api token.
- Auth with email and key.

- Record Content Resolver. (useful for CloudFront)

- Create record on 'serverless deploy'.
- Remove record on 'serverless remove'.
- Command Line Support for c.r.u.d. operations.

Usage

# serverless.yml 

plugins:
  - serverless-cloudflare-dns

custom:
  cloudflare:
    disabled: false                   # Optional, disabled this plugin
    domain: ""                        # Required, your.corp.domain

    auth:
      # Option 1
      # email: ""                     # Required, use aws ssm or something like that
      # key: ""                       # Required, use aws ssm or something like that

      # Option 2
      # apiToken: ""                  # Required, use aws ssm or something like that

    record:
      name: ""                        # Required, subdomain.your.corp.domain

      content: "miapp.com"            # Required, domain.to.redirect
      content: "#{cf:SomeOutput}"     # CloudFormation Output Key.

      type: ""                        # Optional, default = CNAME
      proxied: ""                     # Optional, default = true
      proxiable: ""                   # Optional, default = true

Command Line support

$ sls cloudflare --help
$ sls cloudflare record deploy
$ sls cloudflare record update
$ sls cloudflare record remove
$ sls cloudflare record list
$ sls cloudflare record list -A

Flow

DEPLOY: 
- if record does not exists => Create Record()
- if old cname content not equals to current  => Update Record()
- if record exists => show message(): CF_RECORD_EXISTENT

UPDATE:
- if record exists => Update Record()
- else => show message(): CF_RECORD_NOT_FOUND

REMOVE:
- if record exists => Remove Record()
- else => show message(): CF_RECORD_NOT_FOUND