[AWS] Solve Error: No PEM start marker "b'-----BEGIN PRIVATE KEY-----'" found


AWS Lambda allows you to write customized authorizer for the API gateway, here is the video for Secure your API Gateway with Lambda Authorizer | Step by Step AWS Tutorial.

We can use Firebase to provide the token for our customized authorizer to validate, and use third-party jwt validation library, e.g. python-jose, like the following line:

decoded = jwt.decode(token, key, algorithms=[
                             "RS256"], audience="my-development", options={"verify_exp": False})

If you get the following error:

No PEM start marker "b'-----BEGIN PRIVATE KEY-----'" found

Please try to add .encode('ascii') for the key you provide, like the following line:

decoded = jwt.decode(token, key.encode('ascii'), algorithms=[
                             "RS256"], audience="my-development", options={"verify_exp": False})

References:

Secure your API Gateway with Lambda Authorizer | Step by Step AWS Tutorial

Firebase verify idToken

posted @ 2022-06-17 14:33  Grandyang  阅读(1101)  评论(0编辑  收藏  举报
Fork me on GitHub