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` # 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 # See more details at https://docs.astral.sh/uv/configuration/files/#env
ELASTIC_HOSTS=http://127.0.0.1:9200 ELASTIC_HOSTS=http://host.docker.internal:9200
DYNAMODB_ENDPOINT_URL=http://127.0.0.1:8000
DYNAMODB_PARTITION_KEY=id DYNAMODB_PARTITION_KEY=id
DYNAMODB_SORT_KEY=sk DYNAMODB_SORT_KEY=sk

View File

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

View File

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

View File

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

View File

@@ -7,3 +7,8 @@ region = "sa-east-1"
confirm_changeset = false confirm_changeset = false
capabilities = "CAPABILITY_IAM" capabilities = "CAPABILITY_IAM"
image_repositories = [] 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_CLOUD_ID = os.getenv('ELASTIC_CLOUD_ID')
ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS') ELASTIC_AUTH_PASS = os.getenv('ELASTIC_AUTH_PASS')
ELASTIC_HOSTS = os.getenv('ELASTIC_HOSTS', None)
if ELASTIC_HOSTS: if {'AWS_SAM_LOCAL', 'ELASTIC_HOSTS'}.intersection(os.environ):
ELASTIC_CONN = {'hosts': ELASTIC_HOSTS} ELASTIC_CONN = {'hosts': 'http://host.docker.internal:9200'}
else: else:
ELASTIC_CONN = { ELASTIC_CONN = {
'cloud_id': ELASTIC_CLOUD_ID, 'cloud_id': ELASTIC_CLOUD_ID,

View File

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

View File

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