0

当我调用 AWS sts 担任 lambda 函数中的角色时,该函数在 VPC 上的私有子网中运行,并为 STS 配置了端点。但是,我的请求超时。

我的设置如下:

  • 我在 VPC 中运行附加到私有子网和安全组的 lambda
  • 因为子网是私有的,所以我配置了一个 VPC Endpoint 来访问 STScom.amazonaws.eu-west-1.sts
  • 我的 lambda 是使用较旧的sdk-for-gov1 api 用 golang 编写的:https ://docs.aws.amazon.com/sdk-for-go/api/
  • 我还配置了一个 VPC 端点来访问 S3,它可以正常工作

我的 VPC 端点的 terraform 配置是:

resource "aws_vpc_endpoint" "xxxx-sts" {
  vpc_id = aws_vpc.xxxx.id
  service_name = "com.amazonaws.eu-west-1.sts"
  vpc_endpoint_type = "Interface"
  security_group_ids = [aws_security_group.xxxx.id]
  subnet_ids = [aws_subnet.xxxx.id]
  private_dns_enabled = true
}
4

1 回答 1

1

要解决此问题,请将以下 ENV 键/值添加到您的 lambda 或应用程序环境:

export AWS_STS_REGIONAL_ENDPOINTS='regional'

这会强制 AWS 开发工具包在调用 STS 时使用区域端点而不是全局端点,如此处所述:https ://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html

否则,Go SDK 将默认使用全局 sts 端点https://sts.amazonaws.com用于区域,例如eu-west-1(这发生在以下区域ap-northeast-1, ap-south-1, ap-southeast-1, ap-southeast-2, aws-global, ca-central-1, eu-central-1, eu-north-1, eu-west-1, eu-west-2, eu-west-3, sa-east-1, us-east-1, us-east-2, us-west-1, and us-west-2:)

STS VPC Endpoint 仅为区域 URL 配置,因此当程序尝试访问私有子网中的全局 URL 时,无法建立连接并超时。

于 2022-02-24T16:59:54.310 回答