Cannot reach salesforce Marketing cloud Rest API from AWS App Runner instance

0

I am running a spring boot application on AWS App Runner. The application failed to connect to salesforce Marketing cloud Rest API. Here an example of sample code I am trying (which works perfectly in my machine and in another normal EC2).

   String query = "https://xxxxxxxx.auth.marketingcloudapis.com/v2/token";
   String json = "{\n"
            + "\"grant_type\": \"client_credentials\",\n"
            + "\"client_id\": \"xxxxxx\",\n"
            + "\"client_secret\": \"xxxxxx\""
            + "}\n";

    URL url = new URL(query);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(10000);
    conn.setReadTimeout(10000);
    conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setRequestMethod("POST");

    OutputStream os = conn.getOutputStream();
    os.write(json.getBytes("UTF-8"));
    os.close();

    // read the response
    InputStream in = new BufferedInputStream(conn.getInputStream());
    String text = new BufferedReader(
            new InputStreamReader(in, StandardCharsets.UTF_8))
              .lines()
              .collect(Collectors.joining("\n"));
    System.out.println(text);
gefragt vor 2 Jahren275 Aufrufe
1 Antwort
0

My assumption is that you utilized "Custom VPC" in Networking configurations.

In that case, please make sure the VPC and subnet you selected have routes to the internet, such as NAT GW. Also the NACL and Security Group(s) in the configuration allow the outgoing traffic.

Jason_S
beantwortet vor 2 Jahren
  • Thank you for your quick feedback. I checked VPC and subnets configuration, everything looks OK. I checked also outgoing traffic for ACL and Security Groups, there are no traffic restrictions: allow all traffic, all protocol, all range and source 0.0.0.0/0.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen