Git Product home page Git Product logo

aws-msk-content-streaming's Introduction

Streaming web content with a log-based architecture with Amazon MSK

The repository contains the sample code for the article

Introduction

Example

The repository contains the example of a microblogging service that uses a log-based architecture on Amazon MSK. It consists of a React app that allows you to publish and read articles. A service which implements the gRPC service to publish and subscribe to the messages (articles) that are created. And the AWS CloudFormation templates to run the service on the AWS cloud. The client uses gRPC for Web Clients to communicate with the pub/sub service.

Technologies

Architecture

The architecture for the service is provisioned by two CloudFormation stacks. A core stack that contains naive AWS components like VPC, NAT Gateway and Amazon MSK. And a second app stack, which provisions the app on Fargate with an Application Load Balancer

Application Architecture


Running the example

You can either run the example on

We recommend using AWS Cloud9 to discover the example.


Run on AWS Cloud9

First, you need your own AWS account. Follow these steps if you do not have an account.

⚠️ Running the application will create and consume AWS resources. This will cost you money. Make sure you shut down/remove all resources once you are finished to avoid ongoing charges to your AWS account.

Create a Workspace

⚠️ The AWS Cloud9 workspace should be created by an IAM user with Administrator privileges, not the root account user. Please ensure that you are logged in as an IAM user, not the root account user.

  • Open AWS Cloud9 in the AWS Console.
  • Select Create environment to create a new workspace
  • Name it mskworkshop, click Next step.
  • Choose "t3.small" as Instance Type, take all default values and click Next Step
  • On the overview double check your inputs and click Create Environment

💥 AWS Cloud9 provides a default auto-hibernation setting of 30 minutes for your Amazon EC2 instances created through Cloud9. With this setting, your EC2 instances automatically stop 30 minutes after you close the IDE and restart only when you reopen the IDE.

  • When your workspace is ready, customize the environment by closing the Welcome tab, and opening up a new tab in the workspace.

c9before

  • Your workspace should look like this now.

c9before

💥 If you prefer a different theme, you can choose one by selecting View > Themes > Solarized > Solarized Dark

Update to the latest AWS CLI

  • Run the following command to view the current version of the AWS CLI.
aws --version
  • Update to the latest version.
pip install --user --upgrade awscli
  • Confirm that you have a newer version running.
aws --version

Install tools

The workshop needs some tools to be installed in the environment.

sudo yum install -y jq

This will install Node.js in your Cloud9 environment.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Active the environment.

. ~/.nvm/nvm.sh

Use nvm to install a current version of Node.js.

nvm install node

Later we will use the yarn package manager for installing the client packages.

npm install yarn -g

⚠️ There is an extensive tutorial that walks through the steps of setting up Node.js on an Amazon EC2 instance.

Clone the workshop

You will need to clone the workshop to your AWS Cloud9 workspace.

# First, be sure you are in your environment directory
cd ~/environment

Clone the respository to your environment directory and change into the directory

git clone https://github.com/aws-samples/aws-msk-content-streaming aws-msk-content-streaming && cd $_

Resize the environment

By default Cloud9 has 8GB storage attached. To build the containers you need more space.

make resize

This will resize your environment to 20GB storage.

If encounter an error that the /dev/nvme0n1 device does not exists, then this means you are not running on a Nitro-based architecture. Please replace the devices as explained here with the right ones.

Create an SSH Key

Please run this command to generate SSH Key in Cloud9. This key will be used on the worker node instances to allow ssh access if necessary.

ssh-keygen

⚠️ Press enter 3 times to take the default choices

Upload the public key to your EC2 region.

aws ec2 import-key-pair --key-name ${C9_PROJECT} --public-key-material file://~/.ssh/id_rsa.pub

If you got an error similar to An error occurred (InvalidKey.Format) when calling the ImportKeyPair operation: Key is not in valid OpenSSH public key format then you can try this command instead.

aws ec2 import-key-pair --key-name ${C9_PROJECT} --public-key-material fileb://~/.ssh/id_rsa.pub

Set the environment variable for the KEY_PAIR.

export KEY_PAIR=${C9_PROJECT}

Deploy the workshop

Running the script will deploy the application.

make deploy

This can take a while, as you will create a high available Kafka with Amazon MSK.

⚠️ The deploy scripts detect when you are running the deploy in a AWS Cloud9 workspace. It sets the PROJECT_NAME to your Cloud9 environment name, and extracts the AWS_ACCOUNT_ID and AWS_DEFAULT_REGION. You can override any of these variables

When the process is finished, you can start the React app. It will start the application with the REACT_APP_ENDPOINT environment variable which is set to the URL of the provisioned Application Load Balancer.

make start

When the application is finished to be installed you will see a message that it Compiled successfully!. You can access the preview by selecting Preview > Preview Running Runnin Application from the toolbar. This will open a new tab with the application.

⚠️ you cannot post new content yet. Because we do not have a custom domain, we have not enabled HTTPS with our service. You will have to access the preview URL with HTTP.

Either copy the full url (e.g. https://12345678910.vfs.cloud9.eu-west-1.amazonaws.com/) and replace https with http. Or click on the Pop Out Into New Window button next to the browser bar and then replace it.

c9preview

You can now test it by creating an new item. Give it a title and add some content. If you have finished click Create Post.

You can access the app at localhost:3000 if you run the example on your local machine.

Cleanup

The last step is to cleanup your account. This will delete all created resources.

make delete

Run on your machine

You can either run the example on your own machine, or run on AWS Cloud9. If you run it on your own machine you will have to install some additional tools.

You will have to clone the repository

git clone https://github.com/aws-samples/aws-msk-content-streaming aws-msk-content-streaming && cd $_

and manually set the environment variables for the project.

export PROJECT_NAME=<YOUR_PROJECT_NAME>
export AWS_ACCOUNT_ID=<YOUR_ACCOUNT_ID>
export AWS_DEFAULT_REGION=<YOUR_AWS_REGION>

You can then deploy the CloudFormation Stacks via.

make deploy

Start the development server at localhost:3000 if you run the example on your local machine.

make start

And jump to the cleanup if you have finished playing around with the example.

License

MIT

aws-msk-content-streaming's People

Contributors

dependabot[bot] avatar katallaxie avatar

Stargazers

 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

aws-msk-content-streaming's Issues

make deploy error

hello.

I had an issue when i tried to run "make deploy" command.

I did everything done in the manual before "make deploy" command.

Error messages in console as below.

Deploying Server images to ECR...

An error occurred (InvalidParameterException) when calling the CreateRepository operation: Invalid parameter at 'repositoryName' failed to satisfy constraint: 'must satisfy regular expression '(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*''
make: *** [deploy] Error 255

I checked the deploy.sh script and i think the problem is in here

deploy_images() {
    echo "Deploying Server images to ECR..."
    for app in envoy server; do
        aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${app} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${app}
        docker build -t ${ECR_IMAGE_PREFIX}/${app} -f ${app}.Dockerfile ${DIR} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
        $(aws ecr get-login --no-include-email)
        docker push ${ECR_IMAGE_PREFIX}/${app}
    done
}

I think the expression of repository name is wrong.

I am submitting an issue because i am not sure this is my only problem or it has to be fixed problem.

Thank you.

bzr deprecated

The Alpine docker, which is used for golang, removed bzr so you have to remove it from your RUN apk command line.

Therefore, When i run "make deploy", i get error code as below

Step 4/13 : RUN apk --no-cache add build-base git bzr mercurial gcc
 ---> Running in 9896c26616a1
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  bzr (missing):
    required by: world[bzr]
The command '/bin/sh -c apk --no-cache add build-base git bzr mercurial gcc' returned a non-zero code: 1

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.