diff --git a/src/resty/aws/init.lua b/src/resty/aws/init.lua index 9bfa816..f5b7b2a 100644 --- a/src/resty/aws/init.lua +++ b/src/resty/aws/init.lua @@ -8,6 +8,8 @@ local execute_request = require("resty.aws.request.execute") local split = require("pl.utils").split local tablex = require("pl.tablex") +local AWS_PUBLIC_DOMAIN_PATTERN = "^(.+)(%.amazonaws%.com)$" +local AWS_VPC_ENDPOINT_DOMAIN_PATTERN = "^(.+)(%.vpce%.amazonaws%.com)$" -- case-insensitive lookup help. @@ -326,8 +328,8 @@ local function generate_service_methods(service) -- If the endpoint is a VPC endpoint DNS hostname then we don't need to inject the region -- VPC endpoint DNS hostnames always contain region, see -- https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-access-aws-services.html#interface-endpoint-dns-hostnames - if not service.config._regionalEndpointInjected and not service.config.endpoint:match("^(.+)(%.vpce%.amazonaws%.com)$") then - local pre, post = service.config.endpoint:match("^(.+)(%.amazonaws%.com)$") + if not service.config._regionalEndpointInjected and not service.config.endpoint:match(AWS_VPC_ENDPOINT_DOMAIN_PATTERN) then + local pre, post = service.config.endpoint:match(AWS_PUBLIC_DOMAIN_PATTERN) service.config.endpoint = pre .. "." .. service.config.region .. post service.config.signingRegion = service.config.region service.config._regionalEndpointInjected = true