title: AWS API-Gateway communicating to SNS
body: <p>I am building an API which will be serviced by Lambda functions but I need these to be asynchronous so rather than connecting the API-Gateway directly to the Lambda function I'm using the "AWS Service Proxy" to <em>publish</em> SNS messages and then have the Lambda function subscribe to the relevant SNS topic so it receives delivery of the requests. Here's a picture which illustrates the flow:</p>
  
  <p><a href="https://i.stack.imgur.com/EDa4R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/EDa4R.png" alt="enter image description here"></a></p>
  
  <p>I have tested both the Lambda function in isolation as well pub/sub messaging between SNS and Lambda but I am struggling with the API-Gateway to SNS handoff. Documentation is quite light but what I am assuming right now is that the following attributes must be sent in the POST request:</p>
  
  <ol>
  <li><p><strong>Action</strong>: the API-Gateway offers to set this in the UI and I have put in the <strong>Publish</strong> action which is the appropriate SNS action</p></li>
  <li><p><strong>Message</strong>: the body of the POST message should be a JSON document. It would be passed by the web client and proxied through the gateway to SNS.</p></li>
  <li><p><strong>TopicArn</strong>: indicates the SNS topic that we're publishing to. In my design this would be a static value/endpoint so I'd prefer that the web-client not have to pass this too but if it were easier to do this that would be fine too.</p></li>
  </ol>
  
  <p>I have tried lots of things but am just stuck. Would love to find a good code example somewhere but any help at all would be appreciated.</p>
  
  <hr>
  
  <p>Wanted to add a little more context on my current attempt:</p>
  
  <p>I have tried publishing my API and using Postman to try and get a valid response. Here's the postman screens(one for header vars, one for JSON body):</p>
  
  <p><a href="https://i.stack.imgur.com/apSms.png" rel="noreferrer"><img src="https://i.stack.imgur.com/apSms.png" alt="header variables"></a>
  <a href="https://i.stack.imgur.com/zLzt6.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zLzt6.png" alt="json body"></a></p>
  
  <p>This results in the following error message:</p>
  
  <pre><code>{
     "Error": {
       "Code": "InvalidParameter",
       "Message": "Invalid parameter: TopicArn or TargetArn Reason: no value for required parameter",
       "Type": "Sender"
    },
    "RequestId": "b33b7700-e8a3-58f7-8ebe-39e4e62b02d0"
  }
  </code></pre>
  
  <p>the error seems to indicate that the <strong>TopicArn</strong> parameter is not being sent to SNS but I have included the following in API-Gateway:</p>
  
  <p><a href="https://i.stack.imgur.com/8QkGf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8QkGf.png" alt="enter image description here"></a></p>