-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Export APIGatewayEventRequestContext schema #3409
Comments
Hi @martinnj-adsk, apologies for the delay. I have tried to reproduce the behavior you described and I am not able to make the validation fail even when adding context. I have two functions, one authorizer: export const handler = async (event) => {
return {
principalId: 'user',
policyDocument: {
Version: '2012-10-17',
Statement: [
{
Action: 'execute-api:Invoke',
Effect: 'Allow',
Resource: event.methodArn,
},
],
},
context: {
foo: 'bar',
},
}
} and an API: import { APIGatewayProxyEventSchema } from '@aws-lambda-powertools/parser/schemas/api-gateway';
export const handler = async (event) => {
try {
const parsed = APIGatewayProxyEventSchema.parse(event);
console.log(parsed.requestContext.authorizer);
return {
statusCode: 200,
}
} catch (error) {
console.error(error);
return {
statusCode: 400,
body: JSON.stringify({
message: 'Invalid request',
}),
};
}
} When making a request, the parsing in the API function passes and the log looks like this:
This is because the schemas are not set to With that said, I agree that we should export the |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
Use case
If you have a custom authorizer lambda that adds context to an API Gateway Event, the event won't be valid if using
APIGatewayProxyEventSchema
, as theauthorizer
key is now invalid. Exporting the schema will allow me to extend it, and then define my authorizer context manually.Solution/User Experience
Export APIGatewayEventRequestContext schema.
Powertools for AWS Lambda (TypeScript) version
2.10.0
AWS Lambda function runtime
20.x
Alternative solutions
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: