This repository contains code written in the AWS Cloud Development Kit (CDK)

Overview

AWS AppSync Multi Region Deployment

This repository contains code written in the AWS Cloud Development Kit (CDK) which launches infrastructure across two different regions to demonstrate using AWS AppSync in a multi-region setup.

By default, AWS AppSync endpoints only trigger GraphQL subscriptions in response to data mutations received on that same endpoint. This means that if data is changed by any other source or endpoint, as it is the case of multi-Region deployment, then AppSync is not aware of this change and the subscription will not be triggered. To address this, you can use AWS Lambda functions and Amazon DynamoDB Streams to enable subscriptions to work globally across Regions.

This pre-built AWS CDK solution extends AWS AppSync, enabling global applications with GraphQL subscriptions, and can be deployed to your AWS environment for testing purposes.

Global Serverless Infrastructure

Pre-Requisites

AWS Cloud9 Environment

AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser.

AWS Cloud9 contains a collection of tools that let you code, build, run, test, debug, and release software in the cloud using your internet browser. The IDE offers support for python, pip, AWS CLI, and provides easy access to AWS resources through Identity and Access Management (IAM) user credentials. The IDE includes a terminal with sudo privileges to the managed instance that is hosting your development environment. This makes it easy for you to quickly run commands and directly access AWS services.

Create an AWS Cloud9 environment:

  1. Open the AWS Cloud9 console in the Ireland region (eu-west-1).
  2. Choose Create Environment or open the link.
  3. For Name, enter myDevEnv.
  4. Choose Next step
  5. For Cost-saving setting, choose After four hours.
  6. Select Create a new no-ingress EC2 instance for environment (access via Systems Manager).
  7. Leave the remaining parameters to the default.
  8. Choose Next Step.
  9. Choose Create Environment.
  10. It will start the creation of the Cloud9 environment.

This Cloud 9 environment will come pre installed with the following tools, which are required to launch the infrastructure:

  • AWS CLI
  • Node JS
  • Python v3
  • Pip

AWS CDK Toolkit

The toolkit is a command-line utility which allows you to work with CDK apps. To install the toolkit, run the following command:

npm install -g aws-cdk

Launch the Infrastructure

To launch the infrastructure that is detailed in the CDK stacks, first clone this repository onto the cloud9 machine:

git clone gi[email protected]:aws-samples/aws-appsync-multi-region-deployment.git

Then we can run the setup.sh script, which will launch the two CDK stacks.

cd aws-appsync-multi-region-deployment
bash setup.sh

This script will perform the following tasks automatically:

  1. Setup the Lambda functions by installing the required Node modules and compressing into a .zip package.
  2. Install the required CDK packages and modules
  3. Boostrap both CDK stacks
  4. Launch the primary region CDK stack
  5. Retrieve the ARN of the Global Table stream
  6. Launch the seciondary region CDK stack

Whilst this script is running, it will require your confirmation before infrastructure is launched in your account. On two occasions you will be prompted to type y and press the return key.

Test the Solution

To test the solution, we will open a subscription to AWS AppSync in the Ireland region, and insert some data via a mutation to AWS AppSync in the Sydney region.

  1. Open the AWS AppSync Console in Ireland in one browser window.
  2. In a separate browser window, open the AWS AppSync Console in Sydney
  3. In the Ireland region, open the GraphQL API titled "IrelandGQLSchema" by clicking on its title. Then click on the 'Queries' tab on the menu on the left.
  4. In the Sydney region, open the GraphQL API titled "SydneyGQLSchema" by clicking on its title. Then click on the 'Queries' tab on the menu on the left.
  5. In the Ireland region, enter the following query into the query window and click the play button to open a subscription to the Ireland AppSync endpoint:
subscription MySubscription {
  onCreateItemsModel {
    id
    item
  }
}
  1. In the Sydney region, enter the following mutation into the Query window and click the play button to send the data to the Sydney AppSync endpoint:
mutation MyMutation {
  createItemsModel(input: {id: "Item001", item: "MyItem"}) {
    id
    item
  }
}
  1. In the Ireland region, where you have a subscription open, observe the new data being received by the client. This data has travelled from your client, to the AWS AppSync endpoint in Sydney, into the backend DynamoDB Global Table, replicated to Sydney, triggered the Lambda function in Sydney which notified the AWS AppSync endpoint in Sydney to the new data, which in turn delivered it to the client subscribed to it.

Clean up

To clean up the infrastructure launched, execute the following commands from your cloud9 environment:

cd globalserverless
cdk destroy
cd ../globalserverlesssecondregion
cdk destroy

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Owner
AWS Samples
AWS Samples
Library written in Python that wraps Halo Infinite API.

haloinfinite Library written in Python that wraps Halo Infinite API. Before start It's unofficial, reverse-engineered, neither stable nor production r

Miguel Ferrer 4 Dec 28, 2022
A muti pairs martingle trading bot for Binance exchange.

multi_pairs_martingle_bot English Documentation A muti pairs martingle trading bot for Binance exchange. Configuration { "platform": "binance_futur

51bitquant 62 Nov 16, 2022
DeleteAllBot - Telegram bot to delete all messages in a group

Delete All Bot A star ⭐ from you means a lot to me ! Telegram bot to delete all

Stark Bots 15 Dec 26, 2022
DeKrypt 24 Sep 21, 2022
Python written Rule34 API

Python written Rule34 API

1 Nov 11, 2021
Semplice pagina di informazione per sapere se e quando è uscito Joypad, il podcast a tema videoludico di Matteo Bordone (Corri!), Francesco Fossetti (Salta!) e Alessandro Zampini (Spara! per finta).

È uscito Joypad? Semplice pagina di informazione per sapere se e quando è uscito Joypad, il podcast a tema videoludico di Matteo Bordone (Corri!), Fra

Paolo Donadeo 32 Jan 02, 2023
🐲 Powerfull Discord Token Stealer made in python

🐲 Follow me here 🐲 Discord | YouTube | Github ☕ Usage 💻 Downloading git clone https://github.com/KanekiWeb/Powerfull-Token-Stealer

Kaneki 61 Dec 19, 2022
A wrapper for aqquiring Choice Coin directly through a Python Terminal. Leverages the TinyMan Python-SDK.

CHOICE_TinyMan_Wrapper A wrapper that allows users to acquire Choice Coin directly through their Terminal using ALGO and various Algorand Standard Ass

Choice Coin 16 Sep 24, 2022
Name says it all/Instructions are in README file.

Discord-Webhook-Spammer Name says it all/Instructions are in README file. Setup 1. pip install discord-webhook ( In console, terminal or whatever you

Catto 1 Mar 21, 2022
Stock market bot that will be used to learn about API calls and database connections.

Stock market bot that will be used to learn about API calls and database connections.

1 Dec 24, 2021
A Bot To remove forwarded messages

Forward-Mess-Remover A Bot To remove forwarded messages. uses Remove forwarded messages from Group. Deploy To Heroku

SpamShield 5 Oct 14, 2022
Demonstrating attacks, mitigations, and monitoring on AWS

About Inspectaroo is a web app which allows users to upload images to view metadata. It is designed to show off many AWS services including EC2, Lambd

Alex McCormack 1 Feb 11, 2022
Best DDoS Attack Script Python3, Cyber Attack With 40 Methods

MXDDoS - DDoS Attack Script With 40 Methods (Code Lang - Python 3) Please Don't Attack '.gov' and '.ir' Websites :) Features And Methods 💣 Layer7 GET

7 Mar 07, 2022
A telegram string extractor bot

Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.com/FayasNoushad/String-Extract-Bot/blob/main/LIC

Fayas Noushad 12 Jul 19, 2022
This is a simple collection of instructions and scripts to accompany the computerphile video about mininet and openflow.

How to get going. This project should work on Linux or MacOS. I used Ubuntu 20.04 and provide some notes here. Note, this is certainly not intended as

Richard G. Clegg 70 Jan 02, 2023
A simple Discord bot written in Python

Acolyte A small and simple little Discord bot written in Python that utilizes the discord.py library. Dependencies The bot depends on Python 3.9 and u

0 Jul 17, 2021
A telegram media to pixeldrain stream link bot

Pixeldrain-Bot A telegram media to pixeldrain stream link bot Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - ht

Fayas Noushad 11 Oct 21, 2022
Script to post multiple status(posts) on twitter

Script to post multiple status on twitter (i.e. TWITTER STORM) This program can post upto maximum limit of twitter(around 300 tweets) within seconds.

Sandeep Kumar 4 Sep 09, 2021
tgEasy's Official Assistant Bot and Example Bot

tgEasy Assistant The assistant bot that helps people with tgEasy directly on Telegram. This repository contains the source code of @tgEasyRobot and th

Divide Projects™ 4 Dec 26, 2022
A telegram bot to forward messages automatically when they arrived.

Telegram Message Forwarder Bot A telegram bot, which can forward messages from channel, group or chat to another channel, group or chat automatically.

Adnan Ahmad 181 Jan 07, 2023