We are building a mobile app using Flutter that connects to WebSocket (AWS). The user will SignUp / SignIn to the app using AWS Amplify Auth. After authentication is successful the app will establish a connection to WebSocket on AWS. In order to make our connection to WebSocket secure, we want to use AWS Signer v4 to sign the URL. But we couldn't find any support on AWS Signer v4 for Flutter. Kindly provide us help so that we can use Signer v4 using Flutter something like plugin etc.

Thank You


Solution 1: chunhunghan

You can use package https://pub.dev/packages/sigv4
A Dart library for signing AWS requests with Signature Version 4.
code snippet

final client = Sigv4Client(
  keyId: 'your_access_key_id',
  accessKey: 'your_access_key',
  region: 'eu-west-1',.
  serviceName: 'execute-api',
);


Solution 2: Mohammed Noureldin

I have almost exactly the same use case you have. I have written and released a simple library that can do what you want, creating a presigned URL to connect to AWS WebSocket API Gateway secured by IAM:

https://github.com/MohammedNoureldin/aws_url_signer

Basically you will get your signed URL just like this:

String getSignedWebSocketUrl(
    {String apiId,
    String region,
    String stage,
    String accessKey,
    String secretKey,
    String sessionToken})