-
Notifications
You must be signed in to change notification settings - Fork 22
Add a microservices based sample app to test enablement #18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c1e0542
Add a microservices based sample app to test enablement
AsakerMohd 1d11ca3
removed auto generated code
AsakerMohd 3f19660
removed more boiler plate code that is not needed
AsakerMohd df96f7f
lint
AsakerMohd 673370a
added README and kubernetes config files for eks deployment
AsakerMohd 2e92628
removed some files
AsakerMohd 565de55
adding s3_bucket name as env variable instead of hardcoded
AsakerMohd b9100c0
updated docker compose for local testing
AsakerMohd a612491
updated script for new docker compose
AsakerMohd c8c9884
updated docker build command in script
AsakerMohd c48e9c2
added ec2 deployment instructions
AsakerMohd 359b7f0
fixed sqs
AsakerMohd 55dbf2e
Merge branch 'main' into pythonSampleApp
srprash 616d30e
added copyright headers
AsakerMohd 7051fef
Merge branch 'pythonSampleApp' of https://github.com/aws-observabilit…
AsakerMohd b018177
removed redundant file
AsakerMohd 74133a4
added to vehicle sample app to eachdist for linting
AsakerMohd 5c0d3fc
Merge branch 'main' into pythonSampleApp
AsakerMohd a99f029
fixed lint issues
AsakerMohd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
5 changes: 5 additions & 0 deletions
5
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
static | ||
.idea | ||
.env | ||
db.sqlite3 | ||
*.iml |
19 changes: 19 additions & 0 deletions
19
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Use an official Python runtime as a parent image | ||
FROM python:3.10 | ||
|
||
# Set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
# Set the working directory | ||
WORKDIR /image-service-app | ||
|
||
# Install dependencies | ||
COPY ImageServiceApp/requirements.txt /image-service-app/ | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy the project code into the container | ||
COPY ImageServiceApp/. /image-service-app/ |
18 changes: 18 additions & 0 deletions
18
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/asgi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
ASGI config for ImageServiceApp project. | ||
|
||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
|
||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ImageServiceApp.settings") | ||
|
||
application = get_asgi_application() |
127 changes: 127 additions & 0 deletions
127
...le-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/settings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Django settings for ImageServiceApp project. | ||
|
||
Generated by 'django-admin startproject' using Django 5.0. | ||
|
||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/topics/settings/ | ||
|
||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/5.0/ref/settings/ | ||
""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = False | ||
|
||
ALLOWED_HOSTS = ["*"] | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = "django-insecure-kixr5rw-%ik9i@395&jyjc$p_2%r(^vu0pv=)$$0)z8sjh84=#" | ||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
"django.contrib.admin", | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
"MainService.apps.MainServiceConfig", | ||
] | ||
|
||
MIDDLEWARE = [ | ||
"django.middleware.security.SecurityMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.middleware.common.CommonMiddleware", | ||
"django.middleware.csrf.CsrfViewMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.messages.middleware.MessageMiddleware", | ||
"django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
] | ||
|
||
ROOT_URLCONF = "ImageServiceApp.urls" | ||
|
||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
"DIRS": [], | ||
"APP_DIRS": True, | ||
"OPTIONS": { | ||
"context_processors": [ | ||
"django.template.context_processors.debug", | ||
"django.template.context_processors.request", | ||
"django.contrib.auth.context_processors.auth", | ||
"django.contrib.messages.context_processors.messages", | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = "ImageServiceApp.wsgi.application" | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases | ||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
"NAME": BASE_DIR / "db.sqlite3", | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", | ||
}, | ||
{ | ||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/5.0/topics/i18n/ | ||
|
||
LANGUAGE_CODE = "en-us" | ||
|
||
TIME_ZONE = "UTC" | ||
|
||
USE_I18N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/5.0/howto/static-files/ | ||
|
||
STATIC_URL = "static/" | ||
STATIC_ROOT = os.path.join(BASE_DIR, "static") | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
21 changes: 21 additions & 0 deletions
21
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
URL configuration for ImageServiceApp project. | ||
|
||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/5.0/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.urls import include, path | ||
|
||
urlpatterns = [path("images/", include("MainService.urls"))] |
18 changes: 18 additions & 0 deletions
18
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/wsgi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
WSGI config for ImageServiceApp project. | ||
|
||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
|
||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ImageServiceApp.settings") | ||
|
||
application = get_wsgi_application() |
5 changes: 5 additions & 0 deletions
5
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/admin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# from django.contrib import admin | ||
|
||
# Register your models here. |
8 changes: 8 additions & 0 deletions
8
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/apps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from django.apps import AppConfig | ||
|
||
|
||
class MainServiceConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "MainService" |
5 changes: 5 additions & 0 deletions
5
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# from django.db import models | ||
|
||
# Create your models here. |
5 changes: 5 additions & 0 deletions
5
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/tests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# from django.test import TestCase | ||
|
||
# Create your tests here. |
11 changes: 11 additions & 0 deletions
11
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/urls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.index, name="index"), | ||
path("name/<str:image_name>", views.handle_image, name="image"), | ||
path("remote-image", views.get_remote_image, name="remote-image"), | ||
] |
73 changes: 73 additions & 0 deletions
73
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/MainService/views.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
from threading import Thread | ||
from time import sleep | ||
|
||
import boto3 | ||
import requests | ||
from django.http import HttpResponse, HttpResponseNotAllowed | ||
from django.views.decorators.csrf import csrf_exempt | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
s3_client = boto3.client("s3") | ||
s3_resource = boto3.resource("s3") | ||
sqs = boto3.resource("sqs", region_name="us-west-2") | ||
|
||
|
||
# create resources if they don't exist | ||
# TODO: auto gen bucket name | ||
bucket_name = os.environ.get("S3_BUCKET") | ||
bucket = s3_resource.create_bucket(Bucket=bucket_name) | ||
queue = sqs.create_queue( | ||
QueueName="imageQueue.fifo", Attributes={"FifoQueue": "true", "ContentBasedDeduplication": "true"} | ||
) | ||
|
||
|
||
def read_from_queue(): | ||
while True: | ||
for message in queue.receive_messages(): | ||
image_name = message.body | ||
print("receiving " + image_name + " from the queue") | ||
s3_client.put_object(Bucket=bucket_name, Key=image_name) | ||
message.delete() | ||
sleep(10) | ||
|
||
|
||
thread = Thread(target=read_from_queue) | ||
AsakerMohd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def index(request): | ||
# return all images in s3? | ||
return HttpResponse("Hello, world LOL!") | ||
|
||
|
||
@csrf_exempt | ||
def handle_image(request, image_name): | ||
print(image_name) | ||
if request.method == "POST": | ||
put_image(image_name) | ||
return HttpResponse("Putting to queue") | ||
if request.method == "GET": | ||
return HttpResponse(get_image(image_name)) | ||
return HttpResponseNotAllowed("Only GET requests are allowed!") | ||
|
||
|
||
def get_image(image_name): | ||
s3_object = s3_client.get_object(Bucket=bucket_name, Key=image_name) | ||
return str(s3_object) | ||
|
||
|
||
def get_remote_image(request): | ||
api_url = "https://google.com" | ||
return HttpResponse(requests.get(api_url, timeout=10)) | ||
|
||
|
||
def put_image(image_name): | ||
queue.send_message(MessageBody=image_name, MessageGroupId="1") | ||
print("adding " + image_name + " to the queue") | ||
if not thread.is_alive(): | ||
thread.start() | ||
return HttpResponse("Image added to the queue") |
25 changes: 25 additions & 0 deletions
25
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/manage.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# pylint: skip-file | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ImageServiceApp.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
4 changes: 4 additions & 0 deletions
4
sample-applications/vehicle-dealership-sample-app/ImageServiceApp/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Django~=5.0 | ||
requests~=2.31.0 | ||
boto3~=1.34.14 | ||
python-dotenv~=1.0.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.