|
28 | 28 |
|
29 | 29 | import com.amazonaws.AmazonWebServiceClient; |
30 | 30 | import com.amazonaws.ClientConfiguration; |
| 31 | +import com.amazonaws.SdkClientException; |
31 | 32 | import com.amazonaws.auth.AWSCredentialsProvider; |
32 | 33 | import com.amazonaws.auth.AWSCredentialsProviderChain; |
33 | 34 | import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; |
@@ -146,14 +147,26 @@ public String getActiveProfileName(String clientProfileName) { |
146 | 147 | } |
147 | 148 |
|
148 | 149 | public String getAccountId() { |
149 | | - AWSSecurityTokenService sts = createClient(AWSSecurityTokenServiceClient.class, profileName); |
150 | | - sts.setRegion(getActiveRegion(region)); |
151 | | - return sts.getCallerIdentity(new GetCallerIdentityRequest()).getAccount(); |
| 150 | + try { |
| 151 | + AWSSecurityTokenService sts = createClient(AWSSecurityTokenServiceClient.class, profileName); |
| 152 | + sts.setRegion(getActiveRegion(region)); |
| 153 | + return sts.getCallerIdentity(new GetCallerIdentityRequest()).getAccount(); |
| 154 | + } catch (SdkClientException e) { |
| 155 | + project.getLogger().lifecycle("AWS credentials not configured!"); |
| 156 | + return null; |
| 157 | + } |
| 158 | + |
152 | 159 | } |
153 | 160 |
|
154 | 161 | public String getUserArn() { |
155 | | - AWSSecurityTokenService sts = createClient(AWSSecurityTokenServiceClient.class, profileName); |
156 | | - sts.setRegion(getActiveRegion(region)); |
157 | | - return sts.getCallerIdentity(new GetCallerIdentityRequest()).getArn(); |
| 162 | + try { |
| 163 | + AWSSecurityTokenService sts = createClient(AWSSecurityTokenServiceClient.class, profileName); |
| 164 | + sts.setRegion(getActiveRegion(region)); |
| 165 | + return sts.getCallerIdentity(new GetCallerIdentityRequest()).getArn(); |
| 166 | + } catch (SdkClientException e) { |
| 167 | + project.getLogger().lifecycle("AWS credentials not configured!"); |
| 168 | + return null; |
| 169 | + } |
| 170 | + |
158 | 171 | } |
159 | 172 | } |
0 commit comments