Amazon.SecurityToken.AmazonSecurityTokenServiceClient.AssumeRoleAsync C# (CSharp) Метод

AssumeRoleAsync() публичный Метод

Initiates the asynchronous execution of the AssumeRole operation.
public AssumeRoleAsync ( AssumeRoleRequest request, AssumeRoleResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
request Amazon.SecurityToken.Model.AssumeRoleRequest Container for the necessary parameters to execute the AssumeRole operation on AmazonSecurityTokenServiceClient.
callback AssumeRoleResponse>.AmazonServiceCallback An Action delegate that is invoked when the operation completes.
options Amazon.Runtime.AsyncOptions A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.
Результат void
        public void AssumeRoleAsync(AssumeRoleRequest request, AmazonServiceCallback<AssumeRoleRequest, AssumeRoleResponse> callback, AsyncOptions options = null)
        {
            options = options == null?new AsyncOptions():options;
            var marshaller = new AssumeRoleRequestMarshaller();
            var unmarshaller = AssumeRoleResponseUnmarshaller.Instance;
            Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
            if(callback !=null )
                callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
                    AmazonServiceResult<AssumeRoleRequest,AssumeRoleResponse> responseObject 
                            = new AmazonServiceResult<AssumeRoleRequest,AssumeRoleResponse>((AssumeRoleRequest)req, (AssumeRoleResponse)res, ex , ao.State);    
                        callback(responseObject); 
                };
            BeginInvoke<AssumeRoleRequest>(request, marshaller, unmarshaller, options, callbackHelper);
        }

Same methods

AmazonSecurityTokenServiceClient::AssumeRoleAsync ( AssumeRoleRequest request, System cancellationToken = default(CancellationToken) ) : Task

Usage Example

Пример #1
0
        static async Task Main()
        {
            // Create the SecurityToken client and then display the identity of the
            // default user.
            var roleArnToAssume = "arn:aws:iam::123456789012:role/testAssumeRole";

            var client = new Amazon.SecurityToken.AmazonSecurityTokenServiceClient(REGION);

            // Get and display the information about the identity of the default user.
            var callerIdRequest = new GetCallerIdentityRequest();
            var caller          = await client.GetCallerIdentityAsync(callerIdRequest);

            Console.WriteLine($"Original Caller: {caller.Arn}");

            // Create the request to use with the AssumeRoleAsync call.
            var assumeRoleReq = new AssumeRoleRequest()
            {
                DurationSeconds = 1600,
                RoleSessionName = "Session1",
                RoleArn         = roleArnToAssume
            };

            var assumeRoleRes = await client.AssumeRoleAsync(assumeRoleReq);

            // Now create a new client based on the credentials of the caller assuming the role.
            var client2 = new AmazonSecurityTokenServiceClient(credentials: assumeRoleRes.Credentials);

            // Get and display information about the caller that has assumed the defined role.
            var caller2 = await client2.GetCallerIdentityAsync(callerIdRequest);

            Console.WriteLine($"AssumedRole Caller: {caller2.Arn}");
        }