import code

This commit is contained in:
Fabio Scotto di Santolo
2025-06-10 21:42:42 +02:00
parent d8cd36fa21
commit 11afc7a4ac
4 changed files with 130 additions and 0 deletions

12
Dockerfile Executable file
View File

@@ -0,0 +1,12 @@
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
COPY app.py .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
CMD ["python", "app.py"]

68
app.py Executable file
View File

@@ -0,0 +1,68 @@
from flask import Flask, jsonify, request, Blueprint
from flasgger import Swagger
import logging
app = Flask(__name__)
swagger = Swagger(app)
# Configura il logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Crea un blueprint per l'API v1
api_v1 = Blueprint('api_v1', __name__)
@api_v1.route('/greet', methods=['GET'])
def greet():
"""
Greet a user by name.
---
tags:
- Greeting
parameters:
- name: name
in: query
type: string
required: false
default: World
description: The name to greet.
responses:
200:
description: A greeting message
schema:
type: object
properties:
message:
type: string
example: Hello, World!
"""
name = request.args.get('name', 'World')
message = f'Hello, {name}!'
logger.info(f"[v1] Greeting requested for name: {name}")
return jsonify({'message': message})
# Aggiungi endpoint di health check
@app.route('/health', methods=['GET'])
def health_check():
"""
Health check endpoint.
---
tags:
- Health
responses:
200:
description: Service is healthy
schema:
type: object
properties:
status:
type: string
example: OK
"""
return jsonify({'status': 'OK'}), 200
# Registra il blueprint sotto /api/v1
app.register_blueprint(api_v1, url_prefix='/api/v1')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

2
requirements.txt Executable file
View File

@@ -0,0 +1,2 @@
flask
flasgger

48
task-definition-rev1.json Normal file
View File

@@ -0,0 +1,48 @@
{
"family": "pygreeting",
"containerDefinitions": [
{
"name": "pygreeting",
"image": "public.ecr.aws/t5q0y5r5/pygreeting:latest",
"cpu": 0,
"portMappings": [
{
"name": "pygreeting-5000-tcp",
"containerPort": 5000,
"hostPort": 5000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"healthCheck": {
"command": [
"CMD-SHELL",
"curl --location 'localhost:5000/health' || exit 1"
],
"interval": 30,
"timeout": 5,
"retries": 3
},
"systemControls": []
}
],
"volumes": [],
"placementConstraints": [],
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"enableFaultInjection": false
}