aws-api-gateway - AWS CDK:在本地测试 api 网关时忽略 Api Key?
问题描述
我目前正在使用aws-cdk开发 API,并且正在使用 aws-sam-cli 和 docker 在本地对其进行测试。我想添加 API Key 的要求来调用 API。
这是我的堆栈中的代码:
const api = new apigw.RestApi(this, "MyAPI", {
restApiName: "My API",
description: "BLABLABLA API",
});
const myLambdaIntegration = new apigw.LambdaIntegration(myLambda, {
proxy: false,
});
// Endpoints of the API
api.root.addResource("test").addMethod("GET", myLambdaIntegration, {
apiKeyRequired: true,
});
然后我构建这个堆栈并合成它(npm run build ; cdk synth --no-staging myStack > template.yaml
并尝试在本地测试它
sam local start-api
当我在没有任何 API KEY 的情况下请求我的 api 时,API 会返回我的 lambda 的结果。
我希望它会给我一个错误,比如{"message":"Missing Authentication Token"}
有谁知道发生了什么?我怀疑这是因为授权在本地被忽略但没有找到任何相关信息......
提前致谢!
编辑:部署此堆栈后,API 正确地要求我提供令牌。
解决方案
推荐阅读
- charts - 在 pine 脚本中的一系列条形中找到顶部和底部
- android-studio - 什么是 Android App Bundle (.aab) 文件 MIME 类型?
- mysql - mysql时添加case的多个结果
- css - 如何在 stenciljs 中使用 sass @use?已知问题?
- azure - 来自 Azure Application Insights 警报通知的逻辑应用 HTTP 请求 JSON
- javascript - Javascript 映射数组中的对象数组
- javascript - 使用数组查询数据库的更好方法
- angularjs - 将 keydown 事件定位到 angularJS 自定义指令
- neo4j - Neo4j-graphql-js -- 有没有办法检查可选参数是否存在或不为空?
- c++ - 文件 I/O 分配