【问题标题】:How does one assume a role with the golang xray client?一个人如何在 golang xray 客户端中扮演一个角色?
【发布时间】:2021-09-20 01:33:40
【问题描述】:

每https://aws.amazon.com/xray/faqs/:

Q: My application components run in their own AWS accounts. Can I use X-Ray to collect data across AWS accounts?
Yes, the X-Ray agent can assume a role to publish data into an account different from the one in which it is running. This enables you publish data from various components of your application into a central account.

我知道我可以担任这样的角色:

    st := sts.NewFromConfig(awsConf)
    creds := stscreds.NewAssumeRoleProvider(st, "myRoleArn")
    awsConf.Credentials = aws.NewCredentialsCache(creds)

我知道我可以使用这些凭据创建 xray 服务:

    import xrayv2 "github.com/aws/aws-sdk-go-v2/service/xray" 
    xrayService := xrayv2.NewFromConfig(awsConf)

问题在于 xray 服务是为直接与 xray API 交互而设计的,它没有 xray 客户端提供的任何奇妙的魔力。 我知道的xray客户端是这样配置的:

    import "github.com/aws/aws-xray-sdk-go/xray"
    xray.Configure(xray.Config{
        DaemonAddr:                  "",
        ServiceVersion:              "",
        Emitter:                     nil,
        SamplingStrategy:            nil,
        StreamingStrategy:           nil,
        ExceptionFormattingStrategy: nil,
        ContextMissingStrategy:      nil,
        LogLevel:                    "",
        LogFormat:                   "",
    })

无论我使用的是 aws 还是 aws-v2 库,我都看不到可以为 xray 客户端提供任何类型的 aws conf/凭证提供程序的地方。我可以创建一个自定义发射器,但我希望避免这种情况。

关于如何向github.com/aws/aws-xray-sdk-go/xray 提供凭据缓存的任何想法?

【问题讨论】:

    标签: amazon-web-services go aws-xray aws-sdk-go


    【解决方案1】:

    另一个 S.O.问题帮助我误解了我的误解。 AWS X-Ray 客户端库只是将信息发布到本地运行的守护程序。因此,代码不负责将痕迹传送到 X 射线。

    按照此处的步骤 - https://aws.amazon.com/blogs/compute/application-tracing-on-kubernetes-with-aws-x-ray/

    设置这个变量_ = os.Setenv("AWS_XRAY_DAEMON_ADDRESS", "xray-service.kube-system:2000"),我们能够将库指向本地守护进程。

    那么它是负责转发的守护进程,所以我们通过覆盖 xray ConfigMap 中的RoleArn 来覆盖守护进程运行的角色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-06
      • 2020-01-25
      • 2019-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      相关资源
      最近更新 更多