generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 174
Open
Labels
bugSomething isn't workingSomething isn't workingconfirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementationevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Description
Expected Behavior
I should be able to return an array when using event handlers.
Current Behavior
I get a typescript error when trying to return an array from the handler
Code snippet
import { Router } from '@aws-lambda-powertools/event-handler/experimental-rest';
const ddbDocClient = DynamoDBDocument.from(new DynamoDBClient());
const app = new Router();
app.get('/orders', async () => {
const response = await ddbDocClient.send(
new ScanCommand({
TableName: 'OrdersWorkshop',
})
);
if (response.Items && response.Items.length > 0) {
return response.Items;
}
return { message: 'No orders found' };
});
export const lambdaHandler = (
event: APIGatewayProxyEvent,
context: Context
) => {
app.resolve(event, context);
};
Steps to Reproduce
- Create a lambda function with the code provided
- There's an typescript error on the handler for get orders
Possible Solution
We have defined the HandlerResponse
type as type HandlerResponse = Response | JSONObject;
Instead, it should be type HandlerResponse = Response | JSONValue;
to support both array and objects
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingconfirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementationevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utility
Type
Projects
Status
Backlog