GithubHelp home page GithubHelp logo

alexdebrie / serverless-multi-region Goto Github PK

View Code? Open in Web Editor NEW
20.0 7.0 7.0 13 KB

A multi-region Serverless project using regional endpoints & DynamoDB global tables

Shell 43.46% Python 56.54%

serverless-multi-region's Introduction

Usage (WIP)

  1. Remember to npm install and pip install awscli [--upgrade] (at least version 1.14.24)

  2. Create a Route53 Hosted Zone for your domain (if you don't have one already)

  3. Change the domainName value in the custom block of serverless.yml to match your actual domain:

    custom:
      customDomain:
        domainName: keyvalue.<mydomain>.com
        endpointType: 'regional'
        certificateRegion: ${opt:region}
        createRoute53Record: false
      tableName: "keyvalues"
    
  4. Create keyvalue.<mydomain>.com certificates in ACM in both us-west-2 and eu-central-1. (Oregon and Frankfurt):

$ aws acm request-certificate --domain-name keyvalue.<mydomain>.com --validation-method EMAIL --region us-west-2
$ aws acm request-certificate --domain-name keyvalue.<mydomain>.com --validation-method EMAIL --region eu-central-1

Don't forget to confirm both certificates via email.

  1. Create the custom domains for both regions:

    $ sls create_domain --region us-west-2
    Serverless: 'keyvalue.<mydomain>.com' was created/updated. New domains may take up to 40 minutes to be initialized.
    $ sls create_domain --region eu-central-1
    Serverless: 'keyvalue.<mydomain>.com' was created/updated. New domains may take up to 40 minutes to be initialized.
  2. Deploy your service in us-west-2 (Oregon):

    $ sls deploy --region us-west-2
    ...<deploy output> ...
  3. Test it!

    Set a key in US West:

    $ US_ENDPOINT=$(aws cloudformation describe-stacks --stack-name serverless-keyvalue-dev --region us-west-2 --query 'Stacks[0].Outputs[?OutputKey==`ServiceEndpoint`].OutputValue' --output text)
    $ curl $US_ENDPOINT/mytestkey -d '{"value": "Just testing"}'
    {"key": "mytestkey", "value": "Just testing", "region": "us-west-2"}

    Retrieve the key in Oregon:

    $ curl $US_ENDPOINT/mytestkey
    {"key": "mytestkey", "value": "Just testing", "writeRegion": "us-west-2", "readRegion": "us-west-2"}
  4. Deploy to eu-central-1 (Frankfurt):

    $ sls deploy --region eu-central-1
    ...<deploy output> ...
  5. Clean out your initial table:

    $ bash clean-table.sh
  6. Create your global table:

    $ bash create-global-table.sh
    {
        "GlobalTableDescription": {
            "GlobalTableStatus": "CREATING",
            "GlobalTableName": "keyvalues",
            "ReplicationGroup": [
                {
                    "RegionName": "us-west-2"
                },
                {
                    "RegionName": "eu-central-1"
                }
            ],
            "CreationDateTime": 1516220398.243,
            "GlobalTableArn": "arn:aws:dynamodb::488110005556:global-table/keyvalues"
        }
    }
  7. Test it out!

    Set a key in Oregon:

    $ curl $US_ENDPOINT/mytestkey -d '{"value": "Just testing"}'
    {"key": "mytestkey", "value": "Just testing", "region": "us-west-2"}

    Retrieve the key in Frankfurt:

    EU_ENDPOINT=$(aws cloudformation describe-stacks --stack-name serverless-keyvalue-dev --region eu-central-1 --query 'Stacks[0].Outputs[?OutputKey==`ServiceEndpoint`].OutputValue' --output text)
    $ curl $EU_ENDPOINT/mytestkey
    {"key": "mytestkey", "value": "my value", "writeRegion": "us-west-2", "readRegion": "eu-central-1"}
  8. Set up the Route53 Latency records (don't forget to open the script and configure your domain and subdomain):

    $ bash set-record-sets.sh
    {
        "ChangeInfo": {
            "Status": "PENDING",
            "Comment": "...",
            "SubmittedAt": "2018-01-18T11:16:44.979Z",
            "Id": "/change/C29MDVT401H462"
        }
    }
  9. Curl your key:

    $ curl https://<yourActualDomain>/mytestkey
    {"key": "mytestkey", "value": "my value", "writeRegion": "us-west-2", "readRegion": "eu-central-1"}

    ๐Ÿ’ฅ

serverless-multi-region's People

Contributors

alexcasalboni avatar alexdebrie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

serverless-multi-region's Issues

Issue when trying to update record sets

Hello,

I am getting following error when trying to update the record sets

An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation: [RRSet of type CNAME with DNS name keyvalue.alexandruluca.me.uk. is not permitted as it creates a CNAME or alias loop in the zone., RRSet of type CNAME with DNS name keyvalue.alexandruluca.me.uk. is not permitted as it creates a CNAME or alias loop in the zone.]`

USDOMAIN AND EUROPEDOMAIN are the same and set to keyvalue.alexandruluca.me.uk
subdomain is also keyvalue.alexandruluca.me.uk, shouldn't they be different?

I followed the README step by step

Any ideea how to fix this?

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.