我需要更改哪些配置以允许对AWS Lambda函数进行POST?

时间:2018-10-04 12:41:51

标签: amazon-web-services aws-lambda

我的API网关中有两个端点,它们的设置相同,并指向相同的Lambda函数。唯一的区别是端点之一是GET,而另一个端点是POST。

这是我的代码,正在调用API端点。

    fetch('api/public/libraries/sign-out', {
        method: 'POST',
        headers: new Headers({
           'Accept': 'application/json',
        })
    })
    .then(response => {
        if (!response.ok) {
            throw new Error('Failed with HTTP code ' + response.status);
        }

        return response.json();
    })
    .catch(error => {
        console.log('Error:', error);
    })
    .then(response => {
         console.log(response);
    });

当我将方法设置为GET时,请求将返回成功。 当我将方法设为POST时,我得到index.tsx:59 Error: Error: Failed with HTTP code 403

我已将此API所处的路径模式设置为Allowed HTTP Methods GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE

还有什么可能是错误的?是否可能需要更改一些其他配置才能允许POST?还是响应POST时需要不同的Lambda函数代码?还是可能是其他问题?

我将Node 6用作Lambda上的运行时环境。这是Lambda代码:

exports.handler = (event, context, callback) => {
    callback(null, {
        statusCode: 200,
        headers: {},
        body: JSON.stringify({
            message: 'hello world'
        })
    });
};

0 个答案:

没有答案