Search code examples
javaamazon-web-servicesauthenticationquarkusaws-iot

REST request to AWS from Quarkus backend


I have to send a HTTP request to AWS IoT core to update device shadow. This request should send through Quarkus backend. The current problem is how to Append Authentication headers to the request. Currently there is a authentication problem with this code.

This is the Class used to send the request

import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/things/abc")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient(baseUri = "https://a144gttuytyty10wv7-ats.iot.us-east-1.amazonaws.com")
public interface OrganizationProxy {

@GET
@Path("/shadow?name=shadow-version-1")
Uni<JsonObject> getOrg();

}

This is the client class for test sample get request

import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/organizations")
@ApplicationScoped
public class OrganizationResource {


@Inject
@RestClient
OrganizationProxy organizationProxy;


@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<JsonObject> get() {
return organizationProxy.getOrg();
}

}

I already try to append the Authentication headers. But I didn't found a way to how to do this in the program. My final goal is to send a request to this AWS IoT core device API and get a response.


Solution

  • I connected with AWS Iot Core Device Shadow Rest end point with AWS SignV4.

    https://github.com/kavishkamk/AWS-IoT-Core-REST-endpont-with-AWSV4