I am developing an application in Java and it requires the user to have a policy document. The user enters the access key and secret key. I got AmazonIdentityManagementClient object using the credentials. My application requires "lambda:InvokeFunction". Can any one pls guide me how to check the user policy has lambdainvoke.
3
-
It's not a best practice to give out an AWS access key, secret key to end users of your application. What is the use case that requires this?David Maple– David Maple2017-01-22 11:23:15 +00:00Commented Jan 22, 2017 at 11:23
-
I want to start and stop instances using my application.Viswanath Alikonda– Viswanath Alikonda2017-01-22 13:24:35 +00:00Commented Jan 22, 2017 at 13:24
-
AmazonIdentityManagement iam = new AmazonIdentityManagementClient(credentials); ListAttachedUserPoliciesResult res = iam.listAttachedUserPolicies(req); is throwing Exception in thread "AWT-EventQueue-0" com.amazonaws.services.identitymanagement.model.AmazonIdentityManagementException: 1 validation error detected: Value null at 'userName' failed to satisfy constraint: Member must not be null (Service:AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Request ID: 041cc807-e888-11e6-87da-1fcd46626f3e) at listAttachedUserPoliciesViswanath Alikonda– Viswanath Alikonda2017-02-02 13:34:37 +00:00Commented Feb 2, 2017 at 13:34
Add a comment
|
2 Answers
Try below code to get the attached policy as a string.
AmazonIdentityManagementAsync iam = AmazonIdentityManagementAsyncClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials("",
"")))
.withRegion(Regions.fromName(""))
.withClientConfiguration(getClientConfiguration()).build();
ListAttachedUserPoliciesRequest pre = new ListAttachedUserPoliciesRequest();
pre.setUserName(iam.getUser().getUser().getUserName());
ListAttachedUserPoliciesResult re = iam.listAttachedUserPolicies(pre);
re.getAttachedPolicies().forEach(p -> {
GetPolicyRequest preq = new GetPolicyRequest();
preq.setPolicyArn(p.getPolicyArn());
GetPolicyResult r = iam.getPolicy(preq);
GetPolicyVersionRequest req = new GetPolicyVersionRequest();
req.setPolicyArn(p.getPolicyArn());
req.setVersionId(r.getPolicy().getDefaultVersionId());
GetPolicyVersionResult res = iam.getPolicyVersion(req);
System.out.println(URLDecoder.decode(res.getPolicyVersion().getDocument()));
});
Comments
You can use AmazonIdentityManagementClient.listAttachedUserPolicies() to list the policies attached to a user. This will get you to a list of policy ARNs which you can pass to AmazonIdentityManagementClient.getPolicy().
1 Comment
Viswanath Alikonda
AmazonIdentityManagement iam = new AmazonIdentityManagementClient(credentials); ListAttachedUserPoliciesResult res = iam.listAttachedUserPolicies(req); is throwing Exception in thread "AWT-EventQueue-0" com.amazonaws.services.identitymanagement.model.AmazonIdentityManagementException: 1 validation error detected: Value null at 'userName' failed to satisfy constraint: Member must not be null (Service:AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Request ID: 041cc807-e888-11e6-87da-1fcd46626f3e) at listAttachedUserPolicies