There are more AWS SDK examples available in the AWS Doc SDK Examples
Route requests to an origin closer to the viewer in a CloudFront Functions viewer request event
The following code example shows how to route requests to an origin closer to the viewer in a CloudFront Functions viewer request event.