j256 / cloudwatch-logback-appender

Appender that publishes logback log entries to AWS CloudWatch
ISC License
56 stars 37 forks source link

Fail to retrieve token : com.amazonaws.SdkClientException: Failed to connect to service endpoint #49

Open jrichardsz opened 2 years ago

jrichardsz commented 2 years ago

Expected Behavior

Send the logs to aws cloud watch as other languages does

Current Behavior

Error ar the startup of spring boot application: Fail to retrieve token : com.amazonaws.SdkClientException: Failed to connect to service endpoint

Steps to Reproduce

  1. To have a ready to use classic spring boot api
  2. Add these dependendencies:
    <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.9</version>          
    </dependency>
    <dependency>
    <groupId>com.j256.cloudwatchlogbackappender</groupId>
    <artifactId>cloudwatchlogbackappender</artifactId>
    <version>2.1</version>
    </dependency>
    <dependency>
    <groupId>org.codehaus.janino</groupId>
    <artifactId>janino</artifactId>
    </dependency>
  3. Add this configuration
    <appender name="cloudWatchAppender" class="com.j256.cloudwatchlogbackappender.CloudWatchAppender">
    <region>${META_LOG_AWS_DEFAULT_REGION}</region>
    <logGroup>${META_LOG_AWS_GROUP_NAME}</logGroup>
    <logStream>${META_LOG_AWS_STREAM_NAME}</logStream>
    <accessKeyId>596fe817-5aef-4a13-8d56-f76dc6db26c9</accessKeyId>
    <secretKey>196d6918-466b-48c1-b5c6-af3d51d21f81</secretKey>
    <layout>
        <pattern>[%thread] %level %logger{20} - %msg%n%xThrowable</pattern>
    </layout>
    </appender> 
  4. Start the api in my localhost

Context (Environment)

Additional

On c# and nodejs, the same parameters in the same machine, worked. It was not necessary other configurations

Log

2022-08-31 16:05:24.340 [] [] [] []  WARN 19696 --- [CloudWatchAppender] i.InstanceMetadataServiceResourceFetcher : Fail to retrieve token 

com.amazonaws.SdkClientException: Failed to connect to service endpoint: 
    at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100)
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.getToken(InstanceMetadataServiceResourceFetcher.java:91)
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.readResource(InstanceMetadataServiceResourceFetcher.java:69)
    at com.amazonaws.internal.EC2ResourceFetcher.readResource(EC2ResourceFetcher.java:66)
    at com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:403)
    at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:372)
    at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:368)
    at com.amazonaws.util.EC2MetadataUtils.fetchData(EC2MetadataUtils.java:422)
    at com.amazonaws.util.EC2MetadataUtils.fetchData(EC2MetadataUtils.java:416)
    at com.amazonaws.util.EC2MetadataUtils.getInstanceId(EC2MetadataUtils.java:136)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.lookupInstanceName(CloudWatchAppender.java:712)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.createLogsClient(CloudWatchAppender.java:622)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.writeEvents(CloudWatchAppender.java:534)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.run(CloudWatchAppender.java:497)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:82)
    ... 14 common frames omitted

2022-08-31 16:05:24.342 [] [] [] []  WARN 19696 --- [CloudWatchAppender] com.amazonaws.util.EC2MetadataUtils      : Unable to retrieve the requested metadata (/latest/meta-data/instance-id). Failed to connect to service endpoint: 

com.amazonaws.SdkClientException: Failed to connect to service endpoint: 
    at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100)
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.getToken(InstanceMetadataServiceResourceFetcher.java:91)
    at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.readResource(InstanceMetadataServiceResourceFetcher.java:69)
    at com.amazonaws.internal.EC2ResourceFetcher.readResource(EC2ResourceFetcher.java:66)
    at com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:403)
    at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:372)
    at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:368)
    at com.amazonaws.util.EC2MetadataUtils.fetchData(EC2MetadataUtils.java:422)
    at com.amazonaws.util.EC2MetadataUtils.fetchData(EC2MetadataUtils.java:416)
    at com.amazonaws.util.EC2MetadataUtils.getInstanceId(EC2MetadataUtils.java:136)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.lookupInstanceName(CloudWatchAppender.java:712)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.createLogsClient(CloudWatchAppender.java:622)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.writeEvents(CloudWatchAppender.java:534)
    at com.j256.cloudwatchlogbackappender.CloudWatchAppender$CloudWatchWriter.run(CloudWatchAppender.java:497)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:82)
    ... 14 common frames omitted