zac*_*618 2 amazon-web-services amazon-cognito aws-api-gateway aws-cdk
我正在尝试将 Cognito Authorizer 添加到现有的 API Gateway LambdaRestApi。这是一个完整的代理集成,我希望授权者默认应用于所有方法。我从文档中看不到任何指示如何通过 CDK 完成此操作。
我拥有的:
const userPool = new cognito.UserPool(this, "TestUsers", {
userPoolName: "This is a test"
});
const proxyApi = new apig.LambdaRestApi(this, "HelloFoodSecureProxyApi", {
handler: proxyHandlerLambdaFunction
});
// proxyApi.addDefaultAuthorizor(userPool)
Run Code Online (Sandbox Code Playgroud)
据我所知,我将不得不恢复使用 raw RestApi,添加一个覆盖我的整个API的Resourceand Method,并使用类似的东西手动覆盖底层CFNGET_resource.add_property_override("AuthorizerId", {"Ref": authorizor.auth_id})
我错过了什么吗?有什么建议吗?如果我可以帮助的话,我宁愿不将我的整个 API(轻松地proxy转换为代码)解压到基础设施中。
Gui*_*ume 11
使用defaultMethodOptions对我有用:
const userPool = new cognito.UserPool(this, "TestUsers", {
userPoolName: "This is a test"
});
const authorizer = new apig.CognitoUserPoolsAuthorizer(this, 'Authorizer', {
cognitoUserPools: [userPool]
});
const proxyApi = new apig.LambdaRestApi(this, "HelloFoodSecureProxyApi", {
handler: proxyHandlerLambdaFunction,
defaultMethodOptions: {
authorizationType: apig.AuthorizationType.COGNITO,
authorizer
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2916 次 |
| 最近记录: |