在没有会话的Go AWS开发工具包中创建客户端

How do we create a AWS service client (e.g. EC2, Autoscaling) without using a session, and instead with directly using the sahred credentials, like in boto3.

Using session like this works:

sess := session.New(&aws.Config{
        Region:      aws.String("us-east-1"),
        Credentials: credentials.NewSharedCredentials("", profile),
    })
svc := ec2.New(sess)

However, this does not work:

svc := ec2.New(&aws.Config{
        Region:      aws.String("us-east-1"),
        Credentials: credentials.NewSharedCredentials("", profile),
    })

Error:

cannot use aws.Config literal (type *aws.Config) as type client.ConfigProvider in argument to ec2.New: *aws.Config does not implement client.ConfigProvider (missing ClientConfig method)

How to directly create a client with Go AWS SDK without session?

The SDK needed to avoid a circular dependency, and to do this it used an abstraction called session.Session. However, V2 gets rid of this abstraction by flattening some of the packages :)