Coder Social home page Coder Social logo

serverless-ddns's Introduction

Serverless DDNS

Serverless DDNS management REST API framework created via Chalice.

This framework provides REST API endpoints and methods to realize private Dynamic DNS in cooperation with the Route53 hostzone that registered your own domain. For example, you could register a DNS A record to resolve any domain to your global IP address with PUT method.

$ curl -s -H "Content-type: application/json" -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XPUT http://your-url/hostzone/myhome.example.net
{
  "status": "created",
  "detail": {
    "records": ["203.0.113.111"],
    "type": "A",
    "ttl": 300
  }
}

Setup

This framework can be setup with Chalice.

Requirements

Since Chalice can only deploy AWS Lambda and API Gateway, you must prepare the following items with yourself.

  • Get your own domain name to use with DDNS.
  • Register your domain name with AWS Route53.

Deploy serverless-ddns

NOTE: The deploy process described here is a temporary one. It can be deployed more easily in the future ๐Ÿ™‡ .

What is written here contains a simplified usage of AWS Chalice. It is recommended that you read Chalice Documentation and understand what kind of tool it is.

You could install chalice with pip.

$ pip install chalice

First, clone this repo.

$ git clone https://github.com/chroju/serverless-ddns

Next, create your own IAM policy json from policy-example.json. You must rewrite hosted zone ID of 26L with yours.

$ cp .chalice/{policy-example,policy}.json
$ vim .chalice/policy.json

# ...
#
#   {
#     "Effect": "Allow",
#     "Action": [
#       "route53:ListResourceRecordSets"
#     ],
#     "Resource": "arn:aws:route53:::hostedzone/XXXXXXXXXXXXXX" <= Rewrite here.
#   }
# ]
# ...

You could deploy serverless-ddns at this point. Make your AWS credential file if you have not make it.

$ mkdir ~/.aws
$ cat >> ~/.aws/config
[default]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION

and deploy. If succeeded, you get API endpoint URL.

$ chalice deploy --stage prod
...
https://XXXXXXXXXX.execute-api.ap-northeast-1.amazonaws.com/api/

At the last, setup API key in AWS console. Please reference AWS Developer guide like here (in Japanese).

REST API

After you finished the setup, you could manipulate DDNS with REST API.

GET hostzone

$ curl -s -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XGET http://your-url/hostzone
{
  "status": "exist",
  "record_sets": [
    {
      "records": ["192.168.11.1"],
      "type": "A",
      "ttl": 300
    }
  ]
}

GET hostzone/record

$ curl -s -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XGET http://your-url/hostzone/record
{
  "status": "exist",
  "detail": {
    "records": ["192.168.11.1"],
    "type": "A",
    "ttl": 300
  }
}

PUT hostzone/record

# IP address will be set up with your source global IP.
$ curl -s -H "Content-type: application/json" -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XPUT http://your-url/hostzone/record
{
  "status": "created",
  "detail": {
    "records": ["203.0.113.111"],
    "type": "A",
    "ttl": 300
  }
}

# Response status 400 Bad request
$ curl -s -H "Content-type: application/json" -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XPUT http://your-url/hostzone/record
{
  "status": "error",
  "detail": {
    "message": "There is missing parameters."
  }
}

POST hostzone/record

$ cat record.json
{
  "records": ["192.168.11.1"],
  "type": "A",
  "ttl": 300
}

# Response status 200 OK
$ curl -s -H "Content-type: application/json" -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XPUT http://your-url/hostzone/record -d @record.json
{
  "status": "created",
  "detail": {
    "records": ["192.168.11.1"],
    "type": "A",
    "ttl": 300
  }
}

# Response status 400 Bad request
$ curl -s -H "Content-type: application/json" -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XPUT http://your-url/hostzone/record -d @record.json
{
  "status": "error",
  "detail": {
    "message": "There is missing parameters."
  }
}

DELETE hostzone/record

# Response status 200 OK
$ curl -s -H "Authorization: Token token=XXXXXXXXXXXXXXXXXXXX" -XDELETE http://your-url/hostzone/record
{
  "status": "deleted"
}

LICENSE

MIT

Author

chroju

serverless-ddns's People

Contributors

chroju avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.