Resource icon

Tutorial DDNS with AWS Lambda and Route53

Currently reading
Tutorial DDNS with AWS Lambda and Route53

9
6
NAS
DS214Play
Richard submitted a new resource:

DDNS with AWS Lambda and Route53 - Steps and sample code to setup DDNS with AWS Lambda and Route53

Step 1: Create a new Lambda function
Login to AWS
Go to: Services > Lambda
Click “Create function”
Select “Author from scratch”
Fill in the “Function name” field with whatever name you like
Select Node.js 10.x from “Runtime”
View attachment 351
Click “Create function”.

Step 1.1: Add a Trigger
In the “Designer” component, select “Add trigger”
Under “Select a trigger”, select “API Gateway” (it should be the first in the list).
Under...

Read more about this resource...
 
Is the free tier sufficient? I am sure Lambdas are covered up to millions of calls, but is Route53 going to cost?
I am running a VPS with my own dyndns services - which bases on a simple container that applies the changes to the DNS-API of my provider. Though, the lamda version is way more sexy :)
 
but is Route53 going to cost?
It currently costs $0.50 per "Hosted Zone" per month. In other words, per domain per month, but you can sub-domain until your heart's content at no extra cost. I don't think Lambda is even worth trying to calculate, but that said, the only unknown here is how Synology's DDNS service actually works, and how many requests it's going to make (can't imagine it's more than one per hour, max).

Though, the lamda version is way more sexy :)
I really like it because I already use AWS, but it might be more hassle than it's worth for most people. The tutorial makes it look harder than it is though, because I wanted to detail every single step, just to make it fool-poof. It should only take 10 minutes once you get started.
 
This is fantastic, but I can't get it to work... I've been thinking about this for ages!
DS says
1572633108051.png

If I call the API endpoint in a browser I get:

1572633297878.png

Is there a way I can easily/successfully test or troubleshoot the API?


Thanks,

Declan
 
Hi,

Where you say "“Failed to connect to the server. Please check the network connection of the server.”, this is a misleading error and a known bug", I've worked out what's wrong.

Referring to Interpret Response - No-IP which has the response values.

If you change

JavaScript:
            const response = {
                statusCode: 200,
                body: 'Record Set!',
            };

to be

JavaScript:
            const response = {
                statusCode: 200,
                body: 'good',
            };

You should get a success. You can also change

JavaScript:
        const response = {
            statusCode: 401,
            body: 'Say who now?',
        };

to be


JavaScript:
        const response = {
            statusCode: 200,
            body: 'badauth',
        };

if you like.

Hope these help with the errors!

Regards.
 
That's great, thanks for sharing. I'll update the tutorial later.

Can I just check, you suggest returning a code 200 with text 'badauth' for an error, does the DSM DDNS app handle this gracefully?

JavaScript:
        const response = {
            statusCode: 200,
            body: 'badauth',
        };

Thanks,
Rich
 
Good question, never tested. I couldn't find any documentation which discussed what the statusCode should be so I made the assumption that whoever wrote the original spec was of the "it was a successful request (so 200), but bad data (so 'error' in the body).
 
I think 401 (Unauthorized) is accurate then, pending an official line on what they've written as a handler - some APIs follow HTTP spec more pedantically than others.

I'll test the 200 'good' solution after work some evening.

What version DSM are you using, btw? The original error I mention was introduced quite recently.

Thanks.
 
Whatever the latest is, the NAS auto-updates.

Check out the link I posted; Interpret Response - No-IP or perhaps some of the other dynamic DNS suppliers. For example, I didn't bother adding the IP address to the response and the DSM was quite happy with it.
 
Checked.

Invalidated my password and ran a test.

With a 200 response and 'badauth' body DSM reports 'Authentication failed'. So I'm happy with keeping a 200 response.

The other thing I've done is added a replacement for the word 'wildcard' with '*'

JavaScript:
event.queryStringParameters.hostname.replace('wildcard', '*')

Which lets me setup a wildcard route (I'm never going to have a machine called wildcard!).

All this might be coming across as faults with your original code. Please don't take it that way. I couldn't/wouldn't have got this far without your initial tutorial! So, since I don't think I ever said it; thanks :)
 
The other thing I've done is added a replacement for the word 'wildcard' with '*'

That's a useful comment, certainly some people will want to create sub-domains, but for simplicity I think I'll leave it out from the original tutorial.

All this might be coming across as faults with your original code. Please don't take it that way. I couldn't/wouldn't have got this far without your initial tutorial! So, since I don't think I ever said it; thanks :)

No at all. Glad someone is using it. Two things I love are DSM and AWS so the more these worlds collide, the better. Keep the comments coming. Might stick it into a CloudFormation or TerraForm script in future - it'd be nice to integrate a bunch of other services, too. Writing out manual steps in a tutorial is a bit tedious...
 
That's great, thanks for sharing. I'll update the tutorial later.

Can I just check, you suggest returning a code 200 with text 'badauth' for an error, does the DSM DDNS app handle this gracefully?



Thanks,
Rich
Hi,

Where you say "“Failed to connect to the server. Please check the network connection of the server.”, this is a misleading error and a known bug", I've worked out what's wrong.

Referring to Interpret Response - No-IP which has the response values.

If you change

JavaScript:
            const response = {
                statusCode: 200,
                body: 'Record Set!',
            };

to be

JavaScript:
            const response = {
                statusCode: 200,
                body: 'good',
            };

You should get a success. You can also change

JavaScript:
        const response = {
            statusCode: 401,
            body: 'Say who now?',
        };

to be


JavaScript:
        const response = {
            statusCode: 200,
            body: 'badauth',
        };

if you like.

Hope these help with the errors!

Regards.
I am not sure what I am doing wrong but I have 3 sub-domains and I'd like to update them all using this but I am not familiar with code enough to know what I should do to enable me to do this?
 
I just updated the source code, so it runs on the latest NodeJs 18x, suggested by AWS. and here is the index.mjs:

Code:
import { Route53 } from "@aws-sdk/client-route-53"

const route53 = new Route53();

const USERNAME = 'YOUR_USERNAME';
const PASSWORD = 'YOUR_PASSWORD';
const ROUTE53_COMMENT = 'My Synology Sub-Domain';
const HOSTED_ZONE_ID = 'YOUR_ZONE_ID';

export async function handler(event) {

    if (event.queryStringParameters.username === USERNAME &&
    event.queryStringParameters.password === PASSWORD){

        var params = {
            ChangeBatch: {
                Changes: [
                    {
                    Action: "UPSERT",
                    ResourceRecordSet: {
                    Name: event.queryStringParameters.hostname,
                    ResourceRecords: [
                        {
                        Value: event.queryStringParameters.ip
                        }
                    ],
                    TTL: 60,
                    Type: "A"
                    }
                }
                ],
                Comment: ROUTE53_COMMENT
            },
            HostedZoneId: HOSTED_ZONE_ID
        };

        return route53.changeResourceRecordSets(params)
        .then(res =>{
            console.log('Record Set!');
            const response = {
                statusCode: 200,
                body: 'Record Set!',
            };
            return response;
        });

    } else {
        console.log('Say who now?');
        const response = {
            statusCode: 401,
            body: 'Say who now?',
        };
        return response;
    }
};
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top