Possible to send request directly to Amazon SQS from http (javascript client)? - amazon-web-services

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?

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.

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.

You can use the AWS Javascript API in your JS app, and then use that library to make the SQS API call for you.

Related

Is it possible to return the response from a lambda when using Api gateway with eventbridge?

I have created a micro service architecture which flows as follows:
Api call -> Api gateway -> Eventbridge -> SNS -> Lambda
The reason for this is to use SNS instead of SQS to decouple applications for true serverless compute without the need for lambda to continuously poll sqs, pub sub over push poll.
The trouble is that although the execution is fine and the lambdas run as expected the return received by the user or app is the eventbridge response. I can’t find any docs on how eventbridge handles responses for http requests through API gateway.
Does anyone have any ideas or docs to push me in the right direction.
Thanks!
In your setup it's not possible to have the Lambda response proxied back to the api request initiator, as your client is very much decoupled of the actual request processing.
Almost identical issue was experienced here
You need to rethink the process as a whole:
what operation you want to complete via the API request?
does the processing of the request really need to be asynchronous (= does it take long time to complete?)
can you handle the request with a Lambda function, delegate to sns from there and finally generate desired response back to the client?
So as it turns out the answer is yes and no for anyone coming across this in the future.
With the current setup another database is required and the responses can be inserted into it with a transaction ID. This transaction ID can be generated by the client during the request so a subsequent call to find the response in the table can be made.
Alternatively Websocket or GraphQL api’s or would allow for asynchronous invocation if really depends on your use case and accepted complexity.
Thanks for everyone’s inputs!

How to push mobile application (android/ios) logs to AWS?

This apparently is so simple question but I have been trying hard and came accross many questions and articles but none of them really answers this.
There are many ways to design the architecture after the log is ingested and transferred to AWS. We can use ES, Kinesis and other services.
My problem is how to transfer the application client logs to AWS securly, anywhere, could be S3, Lambda, Kindesis, ElasticSearch. We can surely have an endpoint exposed but that will be open. How to authenticate this to make sure malicious users don't spam our logs? what is the best way to ingest and transfer logs to AWS from mobile applicatios?
Creat an API that collect logs and ingest to kinesis expose it with API gateway use API keys aur authentication API to generate bearer token.
In application create functionality that make API call.
We did this in one of our application successfully
One way is to use Amplify SDK on the client application to log
securely.
Have a look at this link:
https://medium.com/swlh/add-monitoring-to-your-amplify-app-by-using-amplify-framework-d4c43b2bb84b

AWS Service Proxy to SQS

We are exposing a AWS Api Gateway which needs to act as proxy and push body as message to AWS SQS. Our API gateway body can be array of object which we need to parse and send each object to SQS as separate message. Is there any way to achieve this without using Lambda ?
To answer your question, for something as simple as parsing a message and posting to SQS, I don't believe you need Lambda, no. Lambdas are designed for serverless-architecture. That is, when you don't have a server and you still want to run code. In this case, you do have a server behind your API Gateway, so you don't need Lambda (unless you want fancy branching error handling). You can use your API Gateway directly, yep. Here's a code review I found:
https://dzone.com/articles/creating-aws-service-proxy-for-amazon-sqs

Amazon Lambda use cases

Is it possible to make some kind of HTTP request that will trigger Lambda and allow it to build a response for the request?
Is it possible for Lambda to access CloudFront cache directly or somehow get the data it needs. I guess it can be done making HTTP requests to CloudFront, but maybe there is more direct way to do that, no?
Or all this stuff I'm asking here is a peace of **** and I better go and buy a new server or optimize my code (actually, i would like to, but manager wants CloudFront + Lambda, so I'm trying to figure out if that is possible, but the docs don't give me an answer. Am I blind maybe?)
You can expose your lambda function via an API gateway. Then your lambda function can just run code that will access other services/resources (CloundFront, SNS, SQS, etc). Use the AWS SDK to access these services.
See Amazon API Gateway documentation: http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html

AWS Serverless contact form request

I have a static website (a simple landing page) hosted on AWS S3, with Cloudfront enabled in front of it.
I would like to add a public contact form request.
I found some solutions but I would like to know which one is the best.
1/ Front-end JS send a message to an SNS topic and subscribe my email to it (but it means that I need to share an AccessKey in public)
2/ Front-end JS send a message to SNS, trigger a Lambda function which process and send email via SES.
3/ Front-end JS send a POST request to a public API Gateway, trigger a Lambda function which process and send email via SES
4/ Others?
Thank you for your help.
3rd option is the best and easiest one to implement. Also as #Mark said in comments, you don't need to keep your access keys in client side in this case.
3rd for sure. You could even use API Gateway's AWS Service Proxy and call SNS/SES API directly, without the need of using AWS Lambda.
This tutorial covers this use case.