public void AssignRoleToInstance()
        {
            var roleName = Args.Value("Role");
            var client   = new AmazonIdentityManagementServiceClient();

            client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = roleName,
                RoleName            = roleName
            });
        }
Esempio n. 2
0
        public void IdentityManagementServiceAddRoleToInstanceProfile()
        {
            #region c107fac3-edb6-4827-8a71-8863ec91c81f

            var client   = new AmazonIdentityManagementServiceClient();
            var response = client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = "Webserver",
                RoleName            = "S3Access"
            });


            #endregion
        }
Esempio n. 3
0
        static string CreateInstanceProfile()
        {
            var roleName = "ec2-sample-" + RESOURCDE_POSTFIX;
            var client   = new AmazonIdentityManagementServiceClient();

            client.CreateRole(new CreateRoleRequest
            {
                RoleName = roleName,
                AssumeRolePolicyDocument = @"{""Statement"":[{""Principal"":{""Service"":[""ec2.amazonaws.com""]},""Effect"":""Allow"",""Action"":[""sts:AssumeRole""]}]}"
            });

            var statement = new Amazon.Auth.AccessControlPolicy.Statement(Amazon.Auth.AccessControlPolicy.Statement.StatementEffect.Allow);

            statement.Actions.Add(S3ActionIdentifiers.AllS3Actions);
            statement.Resources.Add(new Resource("*"));

            var policy = new Policy();

            policy.Statements.Add(statement);

            client.PutRolePolicy(new PutRolePolicyRequest
            {
                RoleName       = roleName,
                PolicyName     = "S3Access",
                PolicyDocument = policy.ToJson()
            });

            var response = client.CreateInstanceProfile(new CreateInstanceProfileRequest
            {
                InstanceProfileName = roleName
            });

            client.AddRoleToInstanceProfile(new AddRoleToInstanceProfileRequest
            {
                InstanceProfileName = roleName,
                RoleName            = roleName
            });

            return(response.InstanceProfile.Arn);
        }