我创建了这个函数来输出跨区域的 aws 账户的所有账户 ID,但我得到的输出非常难以理解
尝试像 c++ 中那样取消引用
package main
import (
"fmt"
//"github.com/aws/aws-lambda-go/lambda"
// "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
//"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/organizations"
)
func main() {
listAccounts()
}
func listAccounts() {
sess := session.Must(session.NewSession())
svc := organizations.New(sess)
input := &organizations.ListAccountsInput{}
result, err := svc.ListAccounts(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case organizations.ErrCodeAccessDeniedException:
fmt.Println(organizations.ErrCodeAccessDeniedException, aerr.Error())
case organizations.ErrCodeAWSOrganizationsNotInUseException:
fmt.Println(organizations.ErrCodeAWSOrganizationsNotInUseException, aerr.Error())
case organizations.ErrCodeInvalidInputException:
fmt.Println(organizations.ErrCodeInvalidInputException, aerr.Error())
case organizations.ErrCodeServiceException:
fmt.Println(organizations.ErrCodeServiceException, aerr.Error())
case organizations.ErrCodeTooManyRequestsException:
fmt.Println(organizations.ErrCodeTooManyRequestsException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
// fmt.Println(result.Accounts)
var accountList []*string
for _, accountId := range result.Accounts {
accountList = append(accountList, accountId.Id)
}
fmt.Println(accountList)
}
FFIVE
相关分类