-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_lambda_container.sh
More file actions
executable file
·68 lines (58 loc) · 1.86 KB
/
test_lambda_container.sh
File metadata and controls
executable file
·68 lines (58 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Script para testar o container Lambda localmente
# O container Lambda expõe a API na porta 9000
echo "🧪 Testando Container Lambda na porta 9000..."
echo "================================================"
# URL base do container Lambda
LAMBDA_URL="http://localhost:9000/2015-03-31/functions/function/invocations"
# Função para criar evento do API Gateway
create_api_gateway_event() {
local method="$1"
local path="$2"
local body="$3"
cat << EOF
{
"httpMethod": "$method",
"path": "$path",
"pathParameters": null,
"queryStringParameters": null,
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
},
"body": "$body",
"isBase64Encoded": false,
"requestContext": {
"httpMethod": "$method",
"path": "$path",
"stage": "test",
"requestId": "test-request-$(date +%s)",
"identity": {
"sourceIp": "127.0.0.1"
}
}
}
EOF
}
# Teste do endpoint de criação de certificados
echo "📋 Testando POST /api/v1/certificate/create"
echo "Payload: {\"product_id\": \"316\"}"
# Cria o evento
EVENT=$(create_api_gateway_event "POST" "/api/v1/certificate/create" "{\\\"product_id\\\": \\\"316\\\"}")
# Envia requisição para o container Lambda
echo "🚀 Enviando requisição..."
RESPONSE=$(curl -s -X POST "$LAMBDA_URL" \
-H "Content-Type: application/json" \
-d "$EVENT")
echo "📥 Resposta recebida:"
echo "$RESPONSE" | jq '.' 2>/dev/null || echo "$RESPONSE"
echo ""
echo "================================================"
echo "✅ Teste concluído!"
echo ""
echo "💡 Para executar este teste:"
echo " 1. Execute: docker-compose up certified_build_lambda_function"
echo " 2. Em outro terminal: ./test_lambda_container.sh"
echo ""
echo "📚 Documentação AWS Lambda Powertools:"
echo " https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/"