可以使用AWS API Gateway的私有集成与ALB进行集成,并与ALB上的https监听器一起使用。以下是用于将API Gateway私有集成与ALB上的https监听器一起使用的代码示例:
在ALB Listener规则中添加以下内容:
conditions:
- host-header: ["api.example.com"]
actions:
- redirect:
protocol: "HTTPS"
port: "443"
host: "api.example.com" # optional - must match the host header
path: "/#{path}" # optional - preserves the original request path
query: "#{query}" # optional - preserves the original query string
这将设置ALB将所有来自API Gateway的请求重定向到https。如果需要在调用ALB时使用特定的路径,则可以将路径添加到重定向设置中。
然后,在API Gateway集成设置中,'Endpoint Type”设置为“Private”,并在“VPC Link”字段中选择ALB上的VPC连接器。
此外,在Lambda函数中,需要在VPC中运行以与ALB进行通信。要将其放入VPC中,请打开函数的配置选项卡,选择已经存在的VPC和子网,并使用已经配置的安全组,以便您的Lambda函数与ALB进行通信。
通过这些步骤,API Gateway的私有集成和ALB的https监听器可以一起使用。