0

我正在使用 Spring Boot 2.0.9.RELEASE 并试图弄清楚如何为我在 EC2 实例上运行的应用程序配置 CloudWatch 监控。我所做的可以从我对这个问题的回答中看出。但是我遇到了以下异常:

ERROR Oct 23, 2019 12:20:06.881 [pool-2-thread-30] {} io.micrometer.cloudwatch.CloudWatchMeterRegistry:134 - error sending metric data.
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.profile.ProfileCredentialsProvider@32ee6fee: profile file cannot be null]
    at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:136) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.getCredentialsFromContext(AmazonHttpClient.java:1225) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.runBeforeRequestHandlers(AmazonHttpClient.java:801) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:751) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512) ~[aws-java-sdk-core-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchClient.doInvoke(AmazonCloudWatchClient.java:2027) ~[aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchClient.invoke(AmazonCloudWatchClient.java:1994) ~[aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchClient.invoke(AmazonCloudWatchClient.java:1983) ~[aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchClient.executePutMetricData(AmazonCloudWatchClient.java:1754) ~[aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient$20.call(AmazonCloudWatchAsyncClient.java:972) [aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient$20.call(AmazonCloudWatchAsyncClient.java:966) [aws-java-sdk-cloudwatch-1.11.641.jar!/:?]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_191]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_191]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_191]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_191]

奇怪的是,我在之前的尝试中已经设法将指标放入 CloudWatch,但我不知道我破坏了什么。我没有做梦。我仍然可以看到指标^^。

根据我的阅读,我必须对我的 EC2 实例的 IAM 角色做一些事情,但我在这里迷路了。

4

1 回答 1

1

原来,罪魁祸首是以下财产:

cloud.aws.credentials.instanceProfile=false

我在我的配置中有它,因为我在某处读到它需要在本地运行应用程序。然而,在我的情况下,情况并非如此。

不知何故,它滑到了我的生产配置中。正如属性名称所暗示的那样,将其设置为 false 将使 Spring Boot 不使用运行应用程序的 ec2-instance 的配置文件。因此,除非您以其他方式提供凭证,否则应用程序将无法将指标推送到 CloudWatch。

于 2019-10-23T16:52:03.723 回答