Can Amazon Connect be integrated with a backend service? - amazon-web-services

I have been working on developing a chat-bot for an application. I want to use Amazon Connect to power chat-bot. I wanted to understand, if there is a way through which Amazon Connect fetches response from my backend service whenever client posts a question in chatbox.
Expected flow
client (asks question) ---> AWS Connect (calls service) ---> My backend Service (sends response for the question)
Thanks

You can integrate the contact flow with a lambda function, then use the lambda function to call your own backend service.

Related

Integrate aws websocket api with springboot application

**I have created realtime activities website.
currently my website is like this:
frontend page created websocket with endpoint url wss://xyz.com/chat/$scope.userId
In my backend i store a map table of userId-Websocketconnection
when anyone likes image of userId-5 , backend sends notification to websocketConnection whose userId is 5
But now i want to use Aws websocket api
i am confused at several points
how to send userId with websocket connection request to aws websocket api
using aws websocket api ,how can i store this connectionid and user id in my springboot database
when someone likes image of userId-5 , how will i send notification to websocket connection of userId-5
Is it possible using aws websocket api. Please help me
**
That's what exactly APIGateway websocket protocol offers.
You need to connect to websocket, then send a message (json) which has userid in it. Example message below.
{"action": "SUBSCRIBE","payload": {"userId":"123"}}
On APIGateway you can create SUBSCIRBE route and map it to backend endpoint as Integration request where you store connection id into database.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-integration-requests.html
Whenever your spring boot application wants to push notifications, you can make use of AmazonApiGatewayManagementApi and broadcast the message.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html

How can my cloud run service call other cloud run services?

I have a service listening on 'https://myapp.a.run.app/dosomething', but I want to leverage the scalability features of Cloud Run, so in the controller for 'dosomething', I send off 10 requests to 'https://myapp.a.run.app/smalltask'; with my app configured to allow servicing of only one request per instance, I expect 10 instances to spin up, all do their smalltask, and return (all within the timeout period).
But I don't know how to properly authenticate the request, so those 10 requests all result in 403's. For Cloud Run services, I manually pass in a bearer token with the initial request, though I expect to add some api proxy at some point. But without said API proxy, what's the right way to send the request such that it is accepted? The app is running as a user that does have permissions to access the endpoint.
Authenticating service-to-service
If your architecture is using multiple services, these services will likely need to communicate with each other.
You can use synchronous or asynchronous service-to-service communication:
For asynchronous communication, use
Cloud Tasks for one to one asynchronous communication
Pub/Sub for one to many asynchronous communication
Cloud Scheduler for regularly scheduled asynchronous communication.
Cloud Workflows for orchestration services.
For synchronous communication
One service invokes another one over HTTP using its endpoint URL. In this use case, it's a good idea to ensure that each service is only able to make requests to specific services. For instance, if you have a login service, it should be able to access the user-profiles service, but it probably shouldn't be able to access the search service.
First, you'll need to configure the receiving service to accept requests from the calling service:
Grant the Cloud Run Invoker (roles/run.invoker) role to the calling service identity on the receiving service. By default, this identity is PROJECT_NUMBER-compute#developer.gserviceaccount.com.
In the calling service, you'll need to:
Create a Google-signed OAuth ID token with the audience (aud) set to the URL of the receiving service. This value must contain the schema prefix (http:// or https://) and custom domains are currently not supported for the aud value.
Include the ID token in an Authorization: Bearer ID_TOKEN header. You can get this token from the metadata server, while the container is running on Cloud Run (fully managed). If the application is running outside Google Cloud, you can generate an ID token from a service account key file.
For a full guide and examples in Node/Python/Go/Java and others see: Authenticating service-to-service

Is it necessary to use Amazon SNS when using Firebase Cloud Messaging (FCM) on AWS to send notifications?

I have an existing mobile app that can receive push notifications and I have an existing backend application that exposes an API for sending notifications to the app. The backend application uses Firebase Cloud Messaging (FCM), so it could be considered a wrapper around FCM. My backend application uses the Firebase Admin SDK to create messages and send them to Firebase. My customers hit an API exposed by my backend application (so, if we assume that the customer is using Postman, then the flow for sending a message is: Postman->My backend application->Firebase->Mobile app).
Until now I have been running my backend application on a local server, and it works fine. But now I need to deploy this on AWS. My question is: is it necessary to use Amazon SNS or not? I don't really need any additional functionality from AWS, I just want AWS to permit the required communication.
For example, I dont need to go to an AWS interface to enter the token to send messages to my phone. I already have an API exposed through my backend for sending messages. So, should I even bother to set up SNS?
I know that at a minimum I will have to make my firebase project google credentials available to my instance on AWS (in a file located at the path specified using GOOGLE_APPLICATION_CREDENTIALS). What other configuration steps would be needed? Thanks a lot.
After some investigation I found that it is not necessary to use Amazon SNS to achieve what I wanted to achieve.
I was able to deploy my server application (which uses Firebase Cloud Message) to AWS, and the messages arrive on the mobile phones without any problem.
I initialized my backend application using the steps described on the Google Firebase site: https://firebase.google.com/docs/admin/setup

AWS cognito: Store user auth token in backend server

I am developing a react native mobile app and using server side API for managing user related data (backend). Currently I am using AWS cognito for supporting user signup/signin and all the user details are seems to be saved in AWS user pool.
I want to store auth token and user details on my server side, so that I can use this details to fetch user related data. So, I want the following approach to implement
Request:
Mobile App UI -> Server API (backend) -> AWS cognito
Response:
AWS cognito -> Server API (backend) -> Mobile App UI
Is this possible? If not what would be the best approach.
Quick Response
If you are running Springboot in an EC2 instance you can asign a role to that EC2 instance with enought permissions and get data directly from your server app as an Administrator, i mean, using the SDK you can call AWS API requests just with that role, so you can retrieve the user data for all your users.
Other options
I think AWs has some services that make it easy to have this approach.
You can use Amazon Cognito Identity Provider to get credentials for an user and directly in the app you can call for example dynamoDB queries (etc) or you can do AWS API Gateway requests that are executed if the requests have valid credentials, this way you can call Lambdas and make some proccesing. If you need more details you should send more info to know the target of your app and make a better recommendation. Regards,

Should we connect to AWS SNS every time we send a push notification?

I am working on DJANGO server, creating a REST service. The purpose of the service is to send a push notification to the phone number mentioned in the request. I am using AWS SNS service for push notifications. I am establishing connection between my server and AWS every time there is a request to the server. My question is, can we establish a connection once the server is up, like opening a port as we do in a chat application? Or I should establish a connection every time?
I am using Boto package and below is my code
connection = SNSConnection(AWS_ACCESS_KEY,AWS_SECRET_KEY)
connection.publish(message=jsonMessage, subject=title, target_arn=endPoint, message_structure=structure)
The Client classes in the AWS SDK are just wrappers around other lower-level HTTP clients that interface with the HTTP REST methods of the AWS APIs. They are very light-weight so instantiating and destroying a Client instance on each HTTP request to your DJANGO app should be just fine -- you will incur little overhead. I wouldn't worry about shared state clients like you might utilize in Java or other multi-threaded application designs.