add local envs

This commit is contained in:
2025-03-23 22:45:04 -03:00
parent f14bd6b814
commit 2218a6f867
9 changed files with 30 additions and 24 deletions

View File

@@ -1,7 +1,6 @@
# If UV does not load this file, try running `export UV_ENV_FILE=.env`
# See more details at https://docs.astral.sh/uv/configuration/files/#env
ELASTIC_HOSTS=http://127.0.0.1:9200
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
ELASTIC_HOSTS=http://host.docker.internal:9200
DYNAMODB_PARTITION_KEY=id
DYNAMODB_SORT_KEY=sk

View File

@@ -1,8 +1,8 @@
export LOG_LEVEL = DEBUG
export TZ = America/Sao_Paulo
build:
sam build --use-container
deploy:
sam build --use-container && sam deploy
deploy: build
sam deploy --debug
start-api:
sam local start-api --port 4003 --warm-containers eager --debug
start-api: build
sam local start-api

View File

@@ -52,7 +52,7 @@ def lambda_handler(event: dict, context: LambdaContext) -> dict:
return app.resolve(event, context)
if __name__ == '__main__':
print(
app.get_openapi_json_schema(),
)
# if __name__ == '__main__':
# print(
# app.get_openapi_json_schema(),
# )

View File

@@ -7,11 +7,7 @@ requires-python = ">=3.12"
dependencies = ["layercake"]
[dependency-groups]
dev = [
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
"ruff>=0.9.1",
]
dev = ["pytest>=8.3.4", "pytest-cov>=6.0.0", "ruff>=0.9.1"]
[tool.pytest.ini_options]
addopts = "--cov --cov-report html -v"

View File

@@ -7,3 +7,8 @@ region = "sa-east-1"
confirm_changeset = false
capabilities = "CAPABILITY_IAM"
image_repositories = []
[default.local_start_api.parameters]
debug = true
env_vars = "samlocal.env.json"
warm_containers = "EAGER"

View File

@@ -0,0 +1,7 @@
{
"Parameters": {
"USER_TABLE": "test-users",
"ORDER_TABLE": "test-orders",
"ENROLLMENT_TABLE": "test-enrollments"
}
}

View File

@@ -7,10 +7,9 @@ COURSE_TABLE: str = os.getenv('COURSE_TABLE') # type: ignore
ELASTIC_CLOUD_ID = os.getenv('ELASTIC_CLOUD_ID')
ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS')
ELASTIC_HOSTS = os.getenv('ELASTIC_HOSTS', None)
if ELASTIC_HOSTS:
ELASTIC_CONN = {'hosts': ELASTIC_HOSTS}
if {'AWS_SAM_LOCAL', 'ELASTIC_HOSTS'}.intersection(os.environ):
ELASTIC_CONN = {'hosts': 'http://host.docker.internal:9200'}
else:
ELASTIC_CONN = {
'cloud_id': ELASTIC_CLOUD_ID,

View File

@@ -30,13 +30,13 @@ Globals:
LOG_LEVEL: DEBUG
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.1
POWERTOOLS_LOGGER_LOG_EVENT: true
DYNAMODB_PARTITION_KEY: id
USER_TABLE: !Ref UserTable
ORDER_TABLE: !Ref OrderTable
ENROLLMENT_TABLE: !Ref EnrollmentTable
COURSE_TABLE: !Ref CourseTable
ELASTIC_CLOUD_ID: "{{resolve:ssm:/betaeducacao/elastic/cloud_id/str}}"
ELASTIC_AUTH_PASS: "{{resolve:ssm:/betaeducacao/elastic/auth_pass/str}}"
DYNAMODB_PARTITION_KEY: id
Resources:
HttpLog:
@@ -56,7 +56,7 @@ Resources:
Authorizers:
LambdaRequestAuthorizer:
FunctionArn: !GetAtt AuthFunction.Arn
AuthorizerPayloadFormatVersion: 2.0
AuthorizerPayloadFormatVersion: "2.0"
EnableFunctionDefaultPermissions: true
EnableSimpleResponses: true
Identity:

View File

@@ -9,8 +9,8 @@ import layercake.jsonl as jsonl
import pytest
from layercake.dynamodb import DynamoDBPersistenceLayer
PYTEST_TABLE_NAME = os.getenv('PYTEST_TABLE_NAME', 'pytest')
DYNAMODB_ENDPOINT_URL = os.getenv('DYNAMODB_ENDPOINT_URL')
PYTEST_TABLE_NAME = 'pytest'
DYNAMODB_ENDPOINT_URL = 'http://127.0.0.1:8000'
PK = os.getenv('DYNAMODB_PARTITION_KEY', 'pk')
SK = os.getenv('DYNAMODB_SORT_KEY', 'sk')