Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pattern] Backend service #816

Closed
15 of 16 tasks
efekarakus opened this issue Apr 6, 2020 · 1 comment
Closed
15 of 16 tasks

[Pattern] Backend service #816

efekarakus opened this issue Apr 6, 2020 · 1 comment
Assignees
Labels
type/design Issues that are design proposals.

Comments

@efekarakus
Copy link
Contributor

efekarakus commented Apr 6, 2020

Overview

ecs-preview currently has a single application type load balanced web app targeting the use cases of applications that should be accessed from the internet. For example, rendering a website server-side, or building a “gateway” API service that can fan-out to other services.

We'd like to introduce a new app type, a backend app, that is an ECS service that cannot be accessed from the internet but can be reached from other applications in your project with service discovery.

Why do we need a backend app type?

  1. Privacy. If your application is always accessible publicly, then you need to setup authentication (AuthN) and authorization (AuthZ) mechanisms in place to filter only valid requests.
    You can remove this duplication across applications by keeping your apps private and moving these AuthN and AuthZ to a single “gateway” load balanced web app.
  2. Encapsulation. Seamlessly migrate your application from v1 to v2. If your app is always behind a load-balancer, then you’ll have two different paths: “/appv1” and “/appv2”. You have to chase after your clients to ask them to hit the new “/appv2” endpoint instead of “/appv1”.
    However, if the application is in the background, you can seamlessly shift traffic from “appv1.local” to “appv2.local” without your clients being aware of the migration.

An example backend application is an “inventory service”. A RESTful web service that fronts a DynamoDB table which stores all merchandise data.

Proposal

Application initialization

Help menu

Users can initialize a backend app with the existing app init command:

$ ecs-preview app init -h
Creates a new application in a project.
This command is also run as part of "ecs-preview init"

Usage
-----
  ecs-preview app init [flags]
  
Required flags
--------------
  -n, --name        string    Name of the application.
  -d, --dockerfile  string    Path to the Dockerfile.
  -t, --app-type    string    Type of the application create. Valid values are:
                              "Load Balanced Web App", "Backend App".
Load Balanced Web App flags
---------------------------
      --port        uint16    The port on which your Dockerfile listens.

Backend App flags
-------------------
      --port        uint16    The port on which your Dockerfile listens.

Running the command

The user experience while running the command:

$ ecs-preview app init

? Your application's architecture.
A Load Balanced Web App is an internet-facing HTTP server that's behind a 
load balancer. To learn more see: https://github.com/aws/amazon-ecs-cli-v2/wiki/app-types/load-balanced-web-app

A Backend App is a service that is *not* internet-facing, but is reachable
with service discovery. To learn more see: https://github.com/aws/amazon-ecs-cli-v2/wiki/app-types/backend-app
? What type of *infrastructure pattern* best represents your application?
> Load Balanced Web App
> Backend App

? What do you want to *name* this Backend App? inventory

? Which Dockerfile would you like to use for inventory?
> ./Dockerfile

We detected that your Dockerfile exposes port 8080. We'll use that port for service discovery.

We detected "curl -f http://localhost/ || exit 1" as your healthcheck command in 
your Dockerfile with an interval of 5 seconds and 3 retries.

✔ Wrote the manifest for inventory app at ecs-project/inventory/manifest.yml.
Your manifest contains configurations like your container size and healthcheck settings.

✔ Created ECR repositories for application inventory.

If we detect a HEALTHCHECK instruction in the Dockerfile, we display the text above.
If we don’t detect a HEALTHCHECK instruction, then we just don’t set a container health check and don’t print anything.

Manifest

The generated manifest file from app init will look like:

# The manifest for your "inventory" application.
# Read the full specification for the "Backend App" type at:
#  https://github.com/aws/amazon-ecs-cli-v2/wiki/Manifests#backend-app

# Your application name will be used in naming your resources like log groups, services, etc.
name: inventory
 
# Your application is reachable at "http://inventory.${ECS_APP_DISCOVERY_ENDPOINT}:${port}"
# but is not internet-facing.
type: Backend App
 
image:
  # Path to your application's Dockerfile.
  build: ./Dockerfile
  # Port exposed through your container to route traffic to it. 
  port: 8080 


# Optional. Container healthcheck settings. 
# See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html
#
# healthcheck:
# #  The command the container runs to determine if it's healthy.
#  cmd: ["CMD", "curl -f http://localhost/ || exit 1"]
#  interval: 10s   # Time period between healthchecks.
#  retries: 2      # Number of times to retry before container is deemed unhealthy.
#  timeout: 5s     # How long to wait before considering the healthcheck failed.
#  startPeriod: 0s # Grace period within which to provide containers time to bootstrap before failed health checks count towards the maximum number of retries.

# Number of CPU units for the task.
cpu: 256
# Amount of memory in MiB used by the task.
memory: 512
# Number of tasks that should be running in your service.
count: 1

#variables:                    # Pass environment variables as key value pairs.
#  LOG_LEVEL: info

#secrets:                      # Pass secrets from AWS Systems Manager (SSM) Parameter Store.
#  GITHUB_TOKEN: GITHUB_TOKEN  # The key is the name of the environment variable, the value is the name of the SSM      parameter.

# You can override any of the values defined above by environment.
#environments:
#  test:
#    count: 2               # Number of tasks to run for the "test" environment.

Milestones

For the team to have visibility on the necessary work that goes into adding a new application type at the moment:

@efekarakus efekarakus added the type/design Issues that are design proposals. label Apr 6, 2020
@efekarakus efekarakus self-assigned this Apr 6, 2020
@efekarakus efekarakus changed the title [Pattern] Background service [Pattern] Backend service Apr 6, 2020
@efekarakus
Copy link
Contributor Author

efekarakus commented Apr 6, 2020

To illustrate:
Screen Shot 2020-04-06 at 4 44 19 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/design Issues that are design proposals.
Projects
None yet
Development

No branches or pull requests

1 participant