-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for empty region before invoking API in AWS SDK #7523
Conversation
@@ -187,6 +187,9 @@ func newAWSProvider(spec *api.ProviderConfig, configurationLoader AWSConfigurati | |||
} | |||
|
|||
if spec.Region == "" { | |||
if cfg.Region == "" { | |||
return nil, fmt.Errorf("no region code: please set the AWS region to ~/.aws/config file or environment variables") | |||
} | |||
spec.Region = cfg.Region |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 48 to 50 in 4e3d0e4
if pc.Region != "" { | |
options = append(options, config.WithRegion(pc.Region)) | |
} |
Looks like cfg.Region
is set from spec.Region
in newV2Config()
on L184.
We should just move this check on spec.Region
to before L184 and error if it's empty then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your suggestion.
I understood the current logic as the following;
- if
Spec.Region
is not empty,cfg.Region
is set fromspec.Region
innewV2Config()
- if
Spec.Region
is empty,cfg.Region
is set from~/.aws/config
orAWS_REGION
innewV2Config()
So, I think we should check the value of cfg.Region
after L184.
If cfg.Region
is empty, we can determine AWS region is not defined.
//note
cfg, err := newV2Config(spec, credentialsCacheFilePath, configurationLoader)
if err != nil {
return nil, err
}
fmt.Printf("spec.Region : %v\n", spec.Region)
fmt.Printf("cfg.Region : %v\n", cfg.Region)
if cfg.Region == "" {
return nil, fmt.Errorf("AWS Region must be set, please set the AWS Region in AWS config file or as AWS_REGION environment variable")
}
[result]
$ ./eksctl create cluster --dry-run
spec.Region :
cfg.Region : ap-northeast-1
$ rm ~/.aws/config
$ ./eksctl create cluster --dry-run
spec.Region :
cfg.Region :
Error: AWS Region must be set, please set the AWS Region in AWS config file or as AWS_REGION environment variable
$ export AWS_REGION=us-east-1
$ ./eksctl create cluster --dry-run
spec.Region :
cfg.Region : us-east-1
$ ./eksctl create cluster -f sample.yaml --dry-run
spec.Region : ap-northeast-1
cfg.Region : ap-northeast-1
Description
Currently, you will receive the following error if you forget to set the AWS region code.
$ eksctl create cluster
Error: checking AWS STS access – cannot get role ARN for current session: operation error STS: GetCallerIdentity, https response error StatusCode: 0, RequestID: , request send failed, Post "https://sts..amazonaws.com/": Bad Request
When you look closely, you can notice that there is something wrong with this endpoint "https://sts..amazonaws.com/".
However, it is difficult to immediately resolve the problem from this error message.
This PR provides a more understandable error message if you run into the same situation.
I think it helps to navigate the next action to solve the problem.
note:
The Installation document already has "prerequisite" description about aws configs.
https://eksctl.io/installation/#prerequisite
Checklist
README.md
, or theuserdocs
directory)area/nodegroup
) and kind (e.g.kind/improvement
)