Bug: APIGatewayProxyEventModel drops the Lambda authorizer context
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 78/100
Direção de pesquisa
Leia APIGatewayEventAuthorizer e examine tests/events/apiGatewayProxyEventPrincipalId.json para comparar os campos do authorizer com o modelo analisado. Comece verificando os testes do modelo do parser e adicione cobertura para principalId, integrationLatency e chaves de contexto personalizadas, como user_id. O trabalho estará concluído quando o modelo preservar esses valores e os eventos existentes do authorizer do Cognito continuarem sendo analisados.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Expected Behaviour
When a REST API uses a Lambda authorizer, API Gateway puts the authorizer's principalId, the integrationLatency and every key from the authorizer's context map into requestContext.authorizer. APIGatewayProxyEventModel should keep them, so a handler can read something like a tenant ID the authorizer set. The Lambda authorizer output docs cover the context map.
Current Behaviour
APIGatewayEventAuthorizer only declares claims and scopes, so everything else in requestContext.authorizer is dropped. The repo's tests/events/apiGatewayProxyEventPrincipalId.json has this shape (principalId, integrationLatency and a custom user_id).
The APIGatewayProxyEvent data class already exposes these through principal_id, integration_latency and get_context(), and the TypeScript schema keeps them since aws-powertools/powertools-lambda-typescript#5749.
Code snippet
import json
from aws_lambda_powertools.utilities.parser import parse
from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventModel
with open("tests/events/apiGatewayProxyEvent.json") as f:
event = json.load(f)
# What API Gateway sends when a Lambda authorizer returns principalId "user-123"
# and context {"tenantId": "t-9"}
event["requestContext"]["authorizer"] = {
"principalId": "user-123",
"integrationLatency": 42,
"tenantId": "t-9",
}
parsed = parse(event=event, model=APIGatewayProxyEventModel)
print(parsed.requestContext.authorizer)
claims=None scopes=None
Possible Solution
Declare the two fields API Gateway always sends and allow extra keys for the custom context:
class APIGatewayEventAuthorizer(BaseModel):
model_config = ConfigDict(extra="allow")
claims: dict[str, Any] | None = None
scopes: list[str] | None = None
principalId: str | None = None
integrationLatency: int | None = None
With that, the snippet prints principalId='user-123' integrationLatency=42 tenantId='t-9' and the custom keys are in model_extra. It only adds fields, so Cognito authorizer events parse the same as before.
I'm happy to send a PR with tests if that sounds good.
Steps to Reproduce
Run the snippet above from the repo root.
Powertools for AWS Lambda (Python) version
3.40.0
AWS Lambda function runtime
3.13
Packaging format used
PyPi
- Linguagem predominante
- Python
- Estrelas
- 3.3k
- Forks
- 511
- Merge médio
- 3d 8h
- PRs com merge (30d)
- 103
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de aws-powertools/powertools-lambda-python
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
aws-powertools/powertools-lambda-python#8800 ·
Mantenedores costumam responder em até 1 dia
-
Bug: child Logger without a level ignores its parent's log level since 3.6.0Talvez já em andamento @saimcyber assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
aws-powertools/powertools-lambda-python#8778 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Bug: POWERTOOLS_IDEMPOTENCY_DISABLED set to an empty or non-boolean value crashes every invocationTalvez já em andamento @lechakrawarthy assumiu há 11 dias. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
aws-powertools/powertools-lambda-python#8728 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: Redis layer fails the invocation instead of retrying when a record expires between SET NX and GETTalvez já em andamento @coughlmao assumiu há 11 dias. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
aws-powertools/powertools-lambda-python#8727 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 secondsTalvez já em andamento @CJstate assumiu há 11 dias. Abertabug good first issue help wanted idempotency
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
aws-powertools/powertools-lambda-python#8726 · 4 comentários · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de aws-powertools/powertools-lambda-python
Issues semelhantes
-
15-minutes 5-minutes algorithm any-language beginner-friendly c cpp csharp easy go good first issue hacktoberfest help wanted java javascript kotlin python rust swift typescript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Huerte/algo-solutions-python#254 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 86/100
MichaelYcJo/SpecSeal#1543 ·
-
size/s
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
sipyourdrink-ltd/bernstein#7179 ·
Mantenedores costumam responder em até 1 dia
-
good first issue help wanted python up-for-grabs
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
andrewsiah/agentswarm-data-tasks#309 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia