Example AWS Step function to post a record

Hi all,

I have created a Confluent Cloud Cluster and I am trying to publish events to the Kafka topic using the REST HTTP endpoint of the cluster.

Does anyone have an example of how to do that?

I used AWS Step Functions and Lambda to trigger the record creation but did not get any error and also did not see any messages in the topic.

 private static async Task<Task<HttpStatusCode>> SendEventToTopic(String content)
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "xxxxxxxxxxxx");

            HttpContent httpContent = new StringContent(content, Encoding.UTF8);
            var stringTask = client.PostAsync("https://xxxxxxxxxxxx.aws.confluent.cloud:443/kafka/v3/clusters/xcxcxcxcx/topics/payments.json.events/records", httpContent);

            var msg = stringTask;
            Console.Write(msg);
            
        }

The above is then called in a Step Function

public async Task<State> TriggerInitiationEventAsync(State state, ILambdaContext context)
        {
            state.Message = "TriggerInitiationEvent";

            if (!string.IsNullOrEmpty(state.Name))
            {
                state.Message += " " + state.Name;
            }

            string fileName =  "json_templates/Initiation_template.json";

            Console.WriteLine(File.ReadAllText(fileName));
            state.Message = File.ReadAllText(fileName);

            **HttpStatusCode response = await SendEventToTopic(state.Message);**

            state.Message += "responseCode:" + response;  
            return state;
        }

Appreciate the support.

Cheers
Kris

Managed to get logs from my Lambda and the response points to the fact that I have UnsupportedMediaType.

I looked at the Confluent REST API example and it seemed to be the same that I have used

Does anyone know why I could be getting this error?

Cheers
Kris

Ok fixed by adding application/json in a different location as well

HttpContent httpContent = new StringContent(content, Encoding.UTF8, "application/json");

Facing an Unauthorised issue now, but at least the call is working.