Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

646
Views
El autorizador de AWS devuelve 500, mensaje: nulo, con el error AuthorizerConfigurationException en respuesta

Pasé la mayor parte del día tratando de hacer que los autorizadores funcionen, revisé varios ejemplos y todos parecen estar haciendo lo mismo que hace mi código.

Yo uso un marco sin servidor aquí está el código de autorización:

 exports.handler = function (event: APIGatewayTokenAuthorizerEvent): APIGatewayAuthorizerResult { const authorizer = new Authorizer(); try { if (!event.authorizationToken) throw new Error("No token"); const token = event.authorizationToken.split(" ")[1]; const decodedData = authorizer.verifyToken(token) as unknown as User; const policy = generatePolicy(token, event.methodArn); return { ...policy, context: { user: JSON.stringify(decodedData), }, }; } catch (err) { console.log(err); throw "Unauthorized"; } }; const generatePolicy = (principalId: string, methodArn: string) => { return { principalId, policyDocument: { Version: "2012-10-17", Statement: [ { Action: "execute-api:Invoke", Effect: "Allow", Resource: methodArn, }, ], }, }; };

y aquí está la configuración sin servidor

 const serverlessConfiguration: AWS = { service: "user-crud", frameworkVersion: "2", custom: { webpack: { webpackConfig: "./webpack.config.js", includeModules: true, }, }, plugins: ["serverless-webpack"], provider: { name: "aws", runtime: "nodejs14.x", region: "eu-west-1", apiGateway: { minimumCompressionSize: 1024, shouldStartNameWithService: true, }, environment: { AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1", }, lambdaHashingVersion: "20201221", }, functions: { jwtAuthorizer: { handler: "src/api/authorizer.handler", name: "jwtAuthorizer", }, get: { name: "get", handler: "src/api/get.handler", role: "arn:aws:iam::109394173706:role/dynamodb_cloudwatch_full", events: [ { http: { path: "get", method: "get", cors: true, authorizer: "jwtAuthorizer", }, }, ], },

}...

Siempre obtengo una respuesta de 500 cuando el token es correcto y devuelvo el objeto, así que supongo que hay algún problema con el objeto devuelto.

Si el token es incorrecto y lanzo "No autorizado", obtengo la respuesta 401 correcta.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Aparentemente, el controlador debe ser asíncrono, de lo contrario, espera una devolución de llamada... Tiempo bien invertido :|

over 4 years ago · Santiago Trujillo Report

0

Bueno, hay algunas otras razones para obtener,

 { message : null }

error de Api Gateway. Me costó mucho identificar el mío.

  1. Es posible que API Gateway no tenga permiso para invocar el autorizador lambda. Asegúrese de agregar Lambda Invoke Role para su autorizador
  2. No debe modificar el contexto de la solicitud (sin hablar del contexto de la respuesta) . Cada vez que lo intento, obtengo Execution failed due to configuration error: Invalid JSON in response: Unrecognized field "headers", not marked as ignorable en los registros de Api Gateway. Tienes que abordarlo agregando cors con una mención explícita de esos encabezados.
  3. La política de devolución debe cumplir con la versión Lambda Response 1.0. Si desea utilizar el retorno basado en boolean , debe habilitar la respuesta lambda 2.0
  4. Si ha actualizado el nombre de la función lambda del autorizador o algo así, es mejor delete RestApiGateway y crearlo de nuevo. En ocasiones, es posible que los cambios no se actualicen correctamente en CloudFront.
  5. El contexto de respuesta que proporcione solo permitirá tipos de cadena, número o booleanos. Ejemplo,

 function allowPolicy(methodArn) { console.log("Allow Policy") return { "principalId": "apigateway.amazonaws.com", "policyDocument": { "Version": "2012-10-17", "Statement": [ { "Action": "execute-api:Invoke", "Effect": "Allow", "Resource": methodArn } ] }, "context": { "stringValue": "blablabla", "numberValue": 10, "booleanValue": true, } }; }

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!