简体   繁体   English

AWS 放大 REST API Lambda Function 403 {“消息”:“拒绝访问”}

[英]AWS Amplify REST API Lambda Function 403 {"message":"Access Denied"}

I'm using AWS Amplify and for days I've been getting a 403 {"message":"Access Denied"} error when running an API.get request to a lambda function. The ClaudWatch logs are showing that it's an unauthorized request.我正在使用 AWS Amplify,几天来我在运行 API.get 请求到 lambda function 时收到403 {"message":"Access Denied"}错误。ClaudWatch 日志显示这是一个未经授权的请求。 This was once working and if I roll back to a previous deployment in the deployment history in the staging section of the API gateway, it works.这曾经有效,如果我回滚到 API 网关的暂存部分的部署历史中的先前部署,它就有效。 The console logs are showing that the API url are correct when compared with this URL in the staging section in API gateway.控制台日志显示 API url 与 API 网关中暂存部分中的 URL 相比是正确的。 One thing to note is I'm also passing a query string parameter with the api call.需要注意的一件事是,我还通过 api 调用传递了一个查询字符串参数。 CORS has also been enabled and I have deployed the API CORS也已经启用,我已经部署了API

I have configured my API gateway with a Cognito user pool authorizer.我已使用 Cognito 用户池授权方配置我的 API 网关。 My screenshots and code are below.我的截图和代码如下。

在此处输入图像描述

在此处输入图像描述

const authorization = (await Auth.currentSession()).getIdToken().getJwtToken();
        console.log({ authorization });

        const xmlText = await API.get("AbnLookupApi", "/abnLookup", {  
            headers: {
                authorization,
            },
            queryStringParameters: {
                // acnNumber: '30656142479' 
                acnNumber: cbnNumber
            }
        }).then((result) => {
            const xml = parseXml(result);
            console.log(xml);
            const error = xml.getElementsByTagName('exceptionDescription');
            if(error.length > 0)
            {
                processErrors(error);
                return;
            }
            const orgNameElement = xml.getElementsByTagName("organisationName");
            console.log(orgNameElement[0].value); 
            setOrgName(orgNameElement[0].value)
        }).catch((e) => {
            dispatch(setError(e.message));
            console.log(e);
        }); 
    }

I managed to resolve this.我设法解决了这个问题。 I'm not sure exactly how but I think it was when I rolled back to a working version in API gateway and then rolled back to the latest version again.我不确定具体如何,但我认为是当我回滚到 API 网关中的工作版本,然后再次回滚到最新版本时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM