Per the docs, "the endpoints package no longer exists in the AWS SDK for Go V2. Each service client now embeds its required AWS endpoint metadata within the client package." However, the client packages only support endpoint resolution (e.g. ECS's EndpointResolver and EndpointResolverV2). The partition and region metadata needed by ecs-init is only available via the internal awsrulesfn package.
To make the partition and region metadata accessible to ecs-init, use go generate to copy over relevant SDK files [1][2] into an ecs-init package.
Hardcode in partitions and regions that used to be exported as constants.
Add aws-sdk-go-v2 modules to go.mod in ecs-init.
go mod tidy && go mod verify && go mod vendor
make gogenerate-init
Testing
GitHub status checks pass.
Downloaded the ecs-init RPM/DEB packages built from this PR. Installed the packages on EC2 instances running AL2, AL2023, and Ubuntu. Verified that Agent started/stopped/restarted when the systemd ecs-init service was started/stopped/restarted.
New tests cover the changes: no
Description for the changelog
Migrate ecs-init to aws-sdk-go-v2.
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Summary
Migrate the
ecs-init
module toaws-sdk-go-v2
becauseaws-sdk-go
will reach end of support on July 31, 2025.Implementation details
session.Session
toaws.Config
per the docs.ec2metadata.EC2Metadata
toimds.Client
and update client construction per the docs.s3manager.Downloader
tomanager.Downloader
per the docs.endpoints
package,EndpointResolver
andEndpointResolverV2
). The partition and region metadata needed byecs-init
is only available via the internalawsrulesfn
package.ecs-init
, usego generate
to copy over relevant SDK files [1][2] into anecs-init
package.endpoints.PartitionForRegion
toawsrulesfn.GetPartitionForRegion
, which is our own implementation ofgetPartition
. We do not usegetPartition
because it defaults to theaws
partition if it cannot find a match for the region. https://github.com/aws/amazon-ecs-agent/blob/cf8c7a6b65043c550533f330b10aef6d0a342214/ecs-init/config/common.go#L141-L143aws-sdk-go-v2
modules to go.mod inecs-init
.go mod tidy && go mod verify && go mod vendor
make gogenerate-init
Testing
ecs-init
RPM/DEB packages built from this PR. Installed the packages on EC2 instances running AL2, AL2023, and Ubuntu. Verified that Agent started/stopped/restarted when the systemdecs-init
service was started/stopped/restarted.New tests cover the changes: no
Description for the changelog
Migrate ecs-init to aws-sdk-go-v2.
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.