可以通过在Lambda函数中返回一个HTTP重定向响应来实现对POST请求的重定向。下面是一个Node.js Lambda函数的示例代码:
exports.handler = async (event) => {
// 检查请求是否为POST请求
if (event.httpMethod !== 'POST') {
return {
statusCode: 400,
body: 'Bad Request'
};
}
// 构建重定向响应
const response = {
statusCode: 302, // 重定向状态码
headers: {
Location: 'http://example.com' // 重定向URL
},
body: '' // 空的响应主体
};
return response; // 返回重定向响应
};