...
1 package config
2
3 import (
4 "context"
5 "os"
6
7 "github.com/aws/aws-sdk-go-v2/aws"
8 "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
9 )
10
11 const execEnvVar = "AWS_EXECUTION_ENV"
12
13
14 type DefaultsModeOptions struct {
15
16
17
18 Mode aws.DefaultsMode
19
20
21
22
23
24
25 IMDSClient *imds.Client
26 }
27
28 func resolveDefaultsModeRuntimeEnvironment(ctx context.Context, envConfig *EnvConfig, client *imds.Client) (aws.RuntimeEnvironment, error) {
29 getRegionOutput, err := client.GetRegion(ctx, &imds.GetRegionInput{})
30
31 select {
32 case <-ctx.Done():
33 return aws.RuntimeEnvironment{}, err
34 default:
35 }
36
37 var imdsRegion string
38 if err == nil {
39 imdsRegion = getRegionOutput.Region
40 }
41
42 return aws.RuntimeEnvironment{
43 EnvironmentIdentifier: aws.ExecutionEnvironmentID(os.Getenv(execEnvVar)),
44 Region: envConfig.Region,
45 EC2InstanceMetadataRegion: imdsRegion,
46 }, nil
47 }
48
View as plain text