我正在 ec2 机器上的 docker 中设置一个 go 服务器,该服务器使用 aws-sdk-go 模块来调用 AWS api。由以下代码构建的二进制文件在容器内运行时会出现证书问题。
相同的二进制文件运行良好,并在主机上运行时给出预期结果。
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
)
func main() {
svc := autoscaling.New(session.New(), aws.NewConfig().WithRegion("us-east-1"))
input := &autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: []*string{
aws.String("spark-worker-asg"),
},
}
result, err := svc.DescribeAutoScalingGroups(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case autoscaling.ErrCodeInvalidNextToken:
fmt.Println(autoscaling.ErrCodeInvalidNextToken, aerr.Error())
case autoscaling.ErrCodeResourceContentionFault:
fmt.Println(autoscaling.ErrCodeResourceContentionFault, 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)
}
错误日志:
RequestError: send request failed
caused by: Post https://autoscaling.us-east-1.amazonaws.com/: x509: certificate signed by unknown authority
倚天杖
相关分类