@@ -171,6 +171,12 @@ type envConfig struct {
171171 // AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE=IPv6
172172 EC2IMDSEndpointMode endpoints.EC2IMDSEndpointModeState
173173
174+ // Specifies that IMDS clients should not fallback to IMDSv1 if token
175+ // requests fail.
176+ //
177+ // AWS_EC2_METADATA_V1_DISABLED=true
178+ EC2IMDSv1Disabled * bool
179+
174180 // Specifies that SDK clients must resolve a dual-stack endpoint for
175181 // services.
176182 //
@@ -251,6 +257,9 @@ var (
251257 ec2IMDSEndpointModeEnvKey = []string {
252258 "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE" ,
253259 }
260+ ec2MetadataV1DisabledEnvKey = []string {
261+ "AWS_EC2_METADATA_V1_DISABLED" ,
262+ }
254263 useCABundleKey = []string {
255264 "AWS_CA_BUNDLE" ,
256265 }
@@ -393,6 +402,7 @@ func envConfigLoad(enableSharedConfig bool) (envConfig, error) {
393402 if err := setEC2IMDSEndpointMode (& cfg .EC2IMDSEndpointMode , ec2IMDSEndpointModeEnvKey ); err != nil {
394403 return envConfig {}, err
395404 }
405+ setBoolPtrFromEnvVal (& cfg .EC2IMDSv1Disabled , ec2MetadataV1DisabledEnvKey )
396406
397407 if err := setUseDualStackEndpointFromEnvVal (& cfg .UseDualStackEndpoint , awsUseDualStackEndpoint ); err != nil {
398408 return cfg , err
@@ -414,6 +424,24 @@ func setFromEnvVal(dst *string, keys []string) {
414424 }
415425}
416426
427+ func setBoolPtrFromEnvVal (dst * * bool , keys []string ) {
428+ for _ , k := range keys {
429+ value := os .Getenv (k )
430+ if len (value ) == 0 {
431+ continue
432+ }
433+
434+ switch {
435+ case strings .EqualFold (value , "false" ):
436+ * dst = new (bool )
437+ * * dst = false
438+ case strings .EqualFold (value , "true" ):
439+ * dst = new (bool )
440+ * * dst = true
441+ }
442+ }
443+ }
444+
417445func setEC2IMDSEndpointMode (mode * endpoints.EC2IMDSEndpointModeState , keys []string ) error {
418446 for _ , k := range keys {
419447 value := os .Getenv (k )
0 commit comments