add user
This commit is contained in:
@@ -46,6 +46,11 @@ app.include_router(orders.router, prefix='/orders')
|
||||
app.include_router(orgs.custom_pricing, prefix='/orgs')
|
||||
|
||||
|
||||
@app.get('/health')
|
||||
def health():
|
||||
return {'status': 'available'}
|
||||
|
||||
|
||||
@app.exception_handler(ServiceError)
|
||||
def exc_error(exc: ServiceError):
|
||||
return JSONResponse(
|
||||
|
||||
45
api.saladeaula.digital/app/keep_warm.py
Normal file
45
api.saladeaula.digital/app/keep_warm.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import requests
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.utilities.data_classes import (
|
||||
EventBridgeEvent,
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
|
||||
logger = Logger(__name__)
|
||||
tracer = Tracer()
|
||||
urls = ['https://bcs7fgb9og.execute-api.sa-east-1.amazonaws.com/health']
|
||||
|
||||
|
||||
@tracer.capture_lambda_handler
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
results = []
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [executor.submit(ping, url) for url in urls]
|
||||
|
||||
for future in as_completed(futures):
|
||||
results.append(future.result())
|
||||
|
||||
logger.info(results)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def ping(url: str):
|
||||
try:
|
||||
r = requests.get(url, timeout=4)
|
||||
r.raise_for_status()
|
||||
except requests.exceptions.RequestException as exc:
|
||||
return {
|
||||
'url': url,
|
||||
'error': str(exc),
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'url': url,
|
||||
'status': r.status_code,
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
AWSTemplateFormatVersion: "2010-09-09"
|
||||
Transform: "AWS::Serverless-2016-10-31"
|
||||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Transform: 'AWS::Serverless-2016-10-31'
|
||||
|
||||
Parameters:
|
||||
UserTable:
|
||||
@@ -46,11 +46,16 @@ Resources:
|
||||
Properties:
|
||||
RetentionInDays: 90
|
||||
|
||||
ScheduleLog:
|
||||
Type: AWS::Logs::LogGroup
|
||||
Properties:
|
||||
RetentionInDays: 7
|
||||
|
||||
HttpApi:
|
||||
Type: AWS::Serverless::HttpApi
|
||||
Properties:
|
||||
CorsConfiguration:
|
||||
AllowOrigins: ["*"]
|
||||
AllowOrigins: ['*']
|
||||
AllowMethods: [GET, POST, PUT, DELETE, PATCH, OPTIONS]
|
||||
AllowHeaders: [Content-Type, X-Requested-With, Authorization]
|
||||
AllowCredentials: false
|
||||
@@ -59,13 +64,13 @@ Resources:
|
||||
DefaultAuthorizer: OAuth2Authorizer
|
||||
Authorizers:
|
||||
OAuth2Authorizer:
|
||||
IdentitySource: "$request.header.Authorization"
|
||||
IdentitySource: '$request.header.Authorization'
|
||||
JwtConfiguration:
|
||||
issuer: "https://id.saladeaula.digital"
|
||||
issuer: 'https://id.saladeaula.digital'
|
||||
audience:
|
||||
- "1a5483ab-4521-4702-9115-5857ac676851"
|
||||
- "1db63660-063d-4280-b2ea-388aca4a9459"
|
||||
- "78a0819e-1f9b-4da1-b05f-40ec0eaed0c8"
|
||||
- '1a5483ab-4521-4702-9115-5857ac676851'
|
||||
- '1db63660-063d-4280-b2ea-388aca4a9459'
|
||||
- '78a0819e-1f9b-4da1-b05f-40ec0eaed0c8'
|
||||
|
||||
HttpApiFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
@@ -97,12 +102,33 @@ Resources:
|
||||
Path: /{proxy+}
|
||||
Method: ANY
|
||||
ApiId: !Ref HttpApi
|
||||
Health:
|
||||
Type: HttpApi
|
||||
Properties:
|
||||
Path: /health
|
||||
Method: GET
|
||||
ApiId: !Ref HttpApi
|
||||
Auth:
|
||||
Authorizer: NONE
|
||||
|
||||
EventKeepWarmScheduledFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: keep_warm.lambda_handler
|
||||
LoggingConfig:
|
||||
LogGroup: !Ref ScheduleLog
|
||||
Events:
|
||||
ScheduleEvent:
|
||||
Type: ScheduleV2
|
||||
Properties:
|
||||
ScheduleExpression: 'cron(*/3 5-23 * * ? *)'
|
||||
ScheduleExpressionTimezone: America/Sao_Paulo
|
||||
|
||||
Outputs:
|
||||
HttpApiUrl:
|
||||
Description: URL of your API endpoint
|
||||
Value:
|
||||
Fn::Sub: "https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}"
|
||||
Fn::Sub: 'https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}'
|
||||
HttpApiId:
|
||||
Description: Api ID of HttpApi
|
||||
Value:
|
||||
|
||||
5
api.saladeaula.digital/tests/test_keep_warm.py
Normal file
5
api.saladeaula.digital/tests/test_keep_warm.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import keep_warm
|
||||
|
||||
|
||||
def test_keep_warm():
|
||||
keep_warm.lambda_handler({}, {})
|
||||
Reference in New Issue
Block a user