Multiple functions in user_data contain the following aws or similar commands without region specified
aws s3 cp "$src" "$dst"
This results in the following errors for newer regions trying to access s3 bucket objects:
An error occurred (IllegalLocationConstraintException) when calling the PutObject operation: The af-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.
Fix
Appended --region ${aws_region} to the end of all aws commands. AWS region is taken from a data source
data "aws_region" "current" {}
and interpolated into user_data
data "template_file" "user_data_template" {
template = file("${path.module}/templates/user_data_script.sh.tpl")
vars = {
aws_region = data.aws_region.current.name
..
..
}
Details
Fixes #15
This doc https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingBackwardsCompatibility explains that newer regions to not support the legacy global s3 endpoint.
Problem
Multiple functions in user_data contain the following aws or similar commands without region specified
This results in the following errors for newer regions trying to access s3 bucket objects:
Fix
Appended
--region ${aws_region}
to the end of all aws commands. AWS region is taken from a data sourceand interpolated into user_data