在控制台中执行此操作的文档非常清楚,https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html,但在 CDK 中复制确实是痛苦。
我的问题是如何在 CDK 中创建一个支持 s3(中间没有 lambda)的 Rest API,或者至少 apigateway.AwsIntegration 是如何工作的。
我尝试了很多东西,并意识到我是盲编码。我已经在 restApi、lambda、sqs、dynamoDB、s3 之间进行了多次集成,所有这些都非常简单。但是直接把 API Gateway 和 S3 集成在一起,快要哭死了。
我需要一个 restAPI 将请求有效负载直接存储到 S3 存储桶。
这是我已经尝试过的:
向 RestApi 添加策略声明:
const apiResourcePolicy = new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['s3:Put*'],
resources: [bucket.bucketName],
principals: [new ServicePrincipal('apigateway.amazonaws.com')]
})
]
});
const api = new apigateway.RestApi(this, "dispatch-api", {
restApiName: "my api name",
description: "api description",
policy: apiResourcePolicy
});
Run Code Online (Sandbox Code Playgroud)
我认为这应该足以解决权限问题,但是当我将 AWS 集成添加到 API 时,如下所示:
const getS3Integration = new apigateway.AwsIntegration({
service: …Run Code Online (Sandbox Code Playgroud)