Issue
I am returning Data from my AWS account using
GetRoleRequest getRoleRequest = GetRoleRequest.builder().roleName("ec2_role_powered").build();
GetRoleResponse listRoles = iam.getRole(getRoleRequest);
Role role = listRoles.role();
String service = role.assumeRolePolicyDocument();
System.out.println(service);
It is returning role.assumeRolePolicyDocument(); in the following format:
%7B%22Version%22%3A%222012-10-17%22%2C%22Statement%22%3A%5B%7B%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22Service%22%3A%22ec2.amazonaws.com%22%7D%2C%22Action%22%3A%22sts%3AAssumeRole%22%7D%5D%7D
While it is supposed to be in JSON format or something as it is like this in AWS CloudShell console:
How am I supposed to get a string like shown in the picture or decode the %7B like characters to their original format?
Solution
string "%7B%22Version%22%3A%222012-10-17%22%2C%22Statement%22%3A%5B%7B%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22Service%22%3A%22ec2.amazonaws.com%22%7D%2C%22Action%22%3A%22sts%3AAssumeRole%22%7D%5D%7D" is url encoding.
String service = role.assumeRolePolicyDocument();
System.out.println(java.net.URLDecoder.decode(service, StandardCharsets.UTF_8));
Answered By - KuizhiWang

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.