Syl*_*ain 4 amazon-web-services
上下文
我有一个使用AWS trio构建的无服务器Web应用程序:API Gateway + Lambda + DynamoDB.应用程序的第一页发送2个http请求以获取数据并组合响应以打印结果.
/ APIGateway /projects => Lambda (DynamoDB request) \
web app => { } => display data
\ APIGateway /organizations => Lambda (Github API request) /
Run Code Online (Sandbox Code Playgroud)
问题
我第一次要求页面时一切顺利.但是,如果我尝试刷新此页面,我会收到403错误/organizations请求.从那里,如果我等待~3-5分钟,我再次刷新页面,我正确地看到所有数据,我的页面完美显示.有时,GET /organizations失败,有时,它是GET /projects.
为什么我必须等待才能正确刷新页面?我该如何解决?
其他信息
当我有这个403错误时,......
200 OK对OPTIONS /organizations请求的回复GET /organizations在cloudwatch日志中根本看不到请求(OPTIONS请求在那里,但不是GET)响应标头是:
Connection:keep-alive
Content-Length:60
Content-Type:application/json
Date:Mon, 12 Dec 2016 11:31:29 GMT
Via:1.1 af2dd53407c5eae7ddf5c44e27a5dd1b.cloudfront.net (CloudFront)
X-Amz-Cf-Id:Kl1JS1ZCCJuGAmydXv3qDoq3E-rFZrlZbs8Bgvw8RSrb8xsjEyAJNQ==
x-amzn-ErrorType:AccessDeniedException
x-amzn-RequestId:8689b86c-c05e-11e6-b851-7ff70d9a3125
X-Cache:Error from cloudfront
Run Code Online (Sandbox Code Playgroud)
(我不知道为什么我有x-amzn-ErrorType:AccessDeniedException和X-Cache:Error from cloudfront)
我的chrome控制台中有一个CORS错误:
XMLHttpRequest cannot load https://********.execute-api.eu-central-1.amazonaws.com/prod/organizations. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403.
Run Code Online (Sandbox Code Playgroud)
(...即使CORS已启用且Access-Control-Allow-Origin:*存在于OPTIONS响应头中)
谢谢你的帮助!
此问题的根源是自定义授权程序,它为特定资源生成自定义策略.当缓存此策略时,当第二个请求到达时,它与先前生成的请求不匹配并返回错误.
在结果TTL中,以秒为单位,键入0并单击" 更新".现在,您必须部署API以发布更改:
def generatePolicy(principalId, context):
return {
'principalId': principalId,
'policyDocument': {
'Version': '2012-10-17',
'Statement': [{
'Action': 'execute-api:Invoke',
'Effect': 'Allow',
'Resource': 'arn:aws:execute-api:eu-central-1:123456789012:abcdefghij/prod/*'
}]
},
'context': context
}
Run Code Online (Sandbox Code Playgroud)
您可以使用数组在Resource属性中更精确:
'Resource': [
'arn:aws:execute-api:eu-central-1:123456789012:abcdefghij/prod/GET/projects',
'arn:aws:execute-api:eu-central-1:123456789012:abcdefghij/prod/GET/user',
...
]
Run Code Online (Sandbox Code Playgroud)
您可以允许资源的超集和拒绝特定的资源.
看看@Jeremiah的链接:https://forums.aws.amazon.com/thread.jspa?threadID = 225934&tstart = 0
| 归档时间: |
|
| 查看次数: |
13207 次 |
| 最近记录: |