简体   繁体   中英

API Gateway Websocket @Connection endpoint not found

I am attempting to send a socket message to a potentially connected client from the $connect route. I successfully retrieve the connection id from dynamodb. Whenever I attempt to send anything at all, I get the error:

No method found matching route %40connections/aM50DdTXCYcCGEA%3D for http method POST

The code I'm using to send:

Amazon.Runtime.AWSCredentials cd = new Amazon.Runtime.BasicAWSCredentials("*******", "******");

var domainName = request.RequestContext.DomainName;
var endpoint = $"https://{domainName}/{stage}";
context.Logger.LogLine($"API Gateway management endpoint: {endpoint}");

 apiClient = new AmazonApiGatewayManagementApiClient(cd,
                new AmazonApiGatewayManagementApiConfig
                {
                    ServiceURL = endpoint,
                    RegionEndpoint = Amazon.RegionEndpoint.USEast2
                });
Message testMessage = new Message()
            {
                AppId = "TestApp",
                CommandData = "Testing"
            };


MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(testMessage)));

PostToConnectionResponse response = await apiClient.PostToConnectionAsync(new PostToConnectionRequest()
                    {
                        ConnectionId = Uri.EscapeUriString(existing.ConnectionId),
                        Data = stream
                    });

I can't seem to find anything that suggests why the endpoint for POST isn't working (I have a working sample in nodejs, but we need this done in .Net). If anyone has any suggestions how I can go about finding where the issue is it'd be greatly appreciated.

I've confirmed that the endpoint matches what the deployed WebSocket API Gateway url is.

Visual Studio 2017

.Net Core 2.1

AWSSDK.ApiGatewayManagementApi 3.3.100.23

Thanks!

I did more less the same code and it works

        AmazonApiGatewayManagementApiClient client = new AmazonApiGatewayManagementApiClient(new AmazonApiGatewayManagementApiConfig() {
            ServiceURL = "https://" + request.RequestContext.DomainName + "/" + request.RequestContext.Stage
        });

        MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(document)));
        PostToConnectionRequest postRequest = new PostToConnectionRequest()
        {
            ConnectionId = request.RequestContext.ConnectionId,
            Data = stream
        };

        var result = client.PostToConnectionAsync(postRequest);
        result.Wait();

I ended up deleting all IAM roles and re-made them. I guess something was misconfigured or if IAM uses a caching system of any sort maybe it got locked to an older version. It's working now though. Sorry for the delay to post my findings here!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM