Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jrichardsz opened this issue Aug 31, 2022 · 0 comments

Comments

@jrichardsz
Copy link

jrichardsz commented Aug 31, 2022

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>
  1. 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>	
  1. Start the api in my localhost

Context (Environment)

  • Linux
  • Eclipse IDE for Enterprise Java and Web Developers (includes Incubating components) Version: 2021-03 (4.19.0)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant