title: How to integrate API Gateway with s3 in CDK
body: <p>The docs are very clear in doing this in the console, <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html</a>, but replicating in CDK is really painful.</p>
  <p>My question is how to create an Rest API backed with s3 (no lambda in the middle) in CDK, or at least how the apigateway.AwsIntegration works.</p>
  <p>I've tried many things and realized that I was coding blind.
  I have made already multiple integrations between restApi, lambda, sqs, dynamoDB, s3 and all of them were so easy. But integrating API Gateway with S3 directly is about to make me cry.</p>
  <p>I need that a restAPI store the request payload directly to an S3 bucket.</p>
  <p>This is what I already tried:</p>
  <p>Add a policy stament to RestApi:</p>
  <pre class="lang-js prettyprint-override"><code>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, &quot;dispatch-api&quot;, {
          restApiName: &quot;my api name&quot;,
          description: &quot;api description&quot;,
          policy: apiResourcePolicy        
        });
  </code></pre>
  <p>I thought that this should be enough to solve permissions issues, but when I added the AWS Integration to the API, like this:</p>
  <pre class="lang-js prettyprint-override"><code>const getS3Integration = new apigateway.AwsIntegration({
          service: &quot;s3&quot;,        
          path: bucket.bucketName,                               
        });
  
  api.root.addMethod(&quot;PUT&quot;, getS3Integration, {
      requestValidator: requestValidator,
      requestModels: {&quot;application/json&quot;: myModel},
    });
  </code></pre>
  <p>I'm getting:</p>
  <pre><code>1:41:11 PM | CREATE_FAILED        | AWS::ApiGateway::Method           | XXXXXXXXXXXXXXXX
  Role ARN must be specified for AWS integrations (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: xxxxxxxxxxxxxxxxxxxxx; Proxy:
  null)
  </code></pre>
  <p>I don't know how to specify that Role ARN, I did not found that in the docs. Don't know either if add policy to restAPI was necessary. I was trying to replicate the example <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html" rel="nofollow noreferrer">here</a> in CDK.</p>