This topic describes how to install Security Token Service (STS) SDK for Go and provides an example on how to use STS SDK for Go.

Background information

  • Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For more information about STS API operations, see What is STS?.
  • For more information about STS endpoints, see Endpoints.

Install the SDK for Go

You can download the installation packages of the SDKs for Go from the following links:


The following sample code provides an example on how to call the AssumeRole operation by using the SDK for Go. For more information about the parameters, see AssumeRole.

For other operations, you can use OpenAPI Explorer to obtain sample code.

package main

import (

func main() {
    // Construct an Alibaba Cloud client that is used to initiate requests. 
    // Specify the AccessKey ID and AccessKey secret of the requester. The requester can be a Resource Access Management (RAM) user or a RAM role. 
    client, err := sts.NewClientWithAccessKey("cn-hangzhou", "<AccessKeyId>", "<AccessKeySecret>")
    // Construct a request. 
    request := sts.CreateAssumeRoleRequest()
    request.Scheme = "https"
    // Specify request parameters. 
    request.RoleArn = "<RoleArn>"
    request.RoleSessionName = "<RoleSessionName>"
    // Initiate the request and obtain a response. 
    response, err := client.AssumeRole(request)
    if err != nil {
    fmt.Printf("response is %#v\n", response)