Bhanu Prakash Alapati
Bhanu Prakash Alapati

Reputation: 146

Fetch accountId and region inside java application running on AWS ECS

I want to construct an SNS topic ARN dynamically inside the application where the topic name remains constant. I do not want to pass topic ARN as environment variables or I do not want to call createArn either.

Or is there any way to fetch accountId and region from snsClient?

I am using the following dependency:

<dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>sns</artifactId>
            <version>2.15.50</version>
</dependency>

Upvotes: 0

Views: 354

Answers (1)

Vishal Pawar
Vishal Pawar

Reputation: 267

The STS Client's getCallerIdentity method should help you get the information.

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/securitytoken/AWSSecurityTokenServiceClient.html#getCallerIdentity-com.amazonaws.services.securitytoken.model.GetCallerIdentityRequest-

but there could be few other ways to get the information in the ECS container as well.

Upvotes: 1

Related Questions