Is it possible to send a messaging request to Amazon's SQS directly from javascript? I'm trying to create a logging system and would love to bypass sending the request to a middleman server. Also, does anybody know of any alternatives to this solution that I may leverage?
Asked
Active
Viewed 1.9k times
12
-
Is this server-side Javascript (e.g. Node.js) or running in browsers/clients? – Cody Caughlan Dec 09 '11 at 02:18
-
client side. and just to clarify, you can overcome cross domain limitations by using script injection and setting the script element's src to the rest url. if amazon offered to accept an optional callback parameter with which to wrap the response json object, this would be a standard JSONP call. For any of you that care, you can read more about it here: http://en.wikipedia.org/wiki/JSONP – VinnyD Dec 13 '11 at 03:21
3 Answers
8
SQS(and as a matter of fact all aws services) expose REST based apis. You can directly make a http request to the SQS REST api through javascript code. The api documentation id given here.

n00begon
- 3,503
- 3
- 29
- 42

randomuser
- 1,858
- 2
- 17
- 21
-
4The browsers Same-Origin Policy will prevent this. Unless the OP is talking about server-side Javascript (e.g. Node.js) – Cody Caughlan Dec 09 '11 at 02:18
-
@CodyCaughlan, do you [know of an alternative service that does work from a browser](http://stackoverflow.com/questions/13369521/publish-data-from-browser-app-without-writing-my-own-server)? – Drew Noakes Nov 13 '12 at 21:56
-
WebSockets work, so something like Socket.io or Pusher.com should work fine. – eSniff Aug 02 '13 at 22:10
3
Unless you load your Javascript from the same SQS domain as you're trying to send to then no, due the clients/Javascript Same-Origin Policy you wont be able to cross post to SQS.
Your best bet is to use a middle-man server of your own.

Cody Caughlan
- 32,456
- 5
- 63
- 68
-
1actually, is there any way to format the output using json and wrapping it in a callback function? if that were the case, then one can use jsonp to overcome cross domain limitations. – VinnyD Dec 06 '11 at 00:51
0
You can use the AWS Javascript API in your JS app, and then use that library to make the SQS API call for you.

Jan Hertsens
- 323
- 2
- 3