Example usage for com.amazonaws.auth.policy.actions EC2Actions AllEC2Actions

List of usage examples for com.amazonaws.auth.policy.actions EC2Actions AllEC2Actions

Introduction

In this page you can find the example usage for com.amazonaws.auth.policy.actions EC2Actions AllEC2Actions.

Prototype

EC2Actions AllEC2Actions

To view the source code for com.amazonaws.auth.policy.actions EC2Actions AllEC2Actions.

Click Source Link

Document

Represents any action executed on Amazon EC2.

Usage

From source file:org.dasein.prototype.iamc.AWS.java

License:Apache License

public boolean grantAccessToUser(String username, Service service) {
    String entityName;//from w  ww  .  j a  v  a 2  s . c  o m
    Action action;
    switch (service) {
    case ElasticBeanstalk:
        entityName = "iamc-eb";
        action = ElasticBeanstalkActions.AllElasticBeanstalkActions;
        break;
    case EC2:
        entityName = "iamc-ec2";
        action = EC2Actions.AllEC2Actions;
        break;
    default:
        return false;
    }
    try {
        iamClient.getGroup(new GetGroupRequest(entityName));
    } catch (NoSuchEntityException e) {
        iamClient.createGroup(new CreateGroupRequest(entityName));
    }
    Policy policy = new Policy(entityName).withStatements(
            new Statement(Statement.Effect.Allow).withActions(action).withResources(new Resource("*")));
    iamClient.putGroupPolicy(new PutGroupPolicyRequest(entityName, entityName, policy.toJson()));
    iamClient.addUserToGroup(new AddUserToGroupRequest(entityName, username));
    return true;
}