aws-greengrass / aws-greengrass-gdk-cli

The Greengrass Development Kit - Command Line Interface (GDK CLI) is a tool that helps you create Greengrass V2 components either using templates or community repositories.
https://docs.aws.amazon.com/greengrass/v2/developerguide/greengrass-development-kit-cli.html
Apache License 2.0
28 stars 18 forks source link

(gdk): component publish is throwing InvalidRegionError in Windows 10 #287

Closed gagan1469 closed 4 months ago

gagan1469 commented 4 months ago

Describe the bug component publish is throwing InvalidRegionError in Windows 10

To Reproduce

  1. Git clone the gdk repo and install in local environment using pip install -e .
  2. Open custom greengrass component project with recipe and gdk-config.json
  3. Set environment variables for AWS_REGION, short-term credentials (AWS_ACCESS_KEY_ID=ccc, AWS_SECRET_ACCESS_KEY=xxx, AWS_SESSION_TOKEN=xxx)
  4. Run gdk component build from folder (successful)
  5. Run gdk component publish from folder (fails)

Expected behavior Component should have published to S3 bucket in account. The same code/setup works in Amazon Linux 2023 OS.

Actual behavior Throws error \botocore\utils.py", line 1320, in validate_region_name raise InvalidRegionError(region_name=region_name) botocore.exceptions.InvalidRegionError: Provided region_name '' doesn't match a supported format.

Environment

Additional context Workaround by hard-coding the region in Line 149 of aws-greengrass-gdk-cli\gdk\commands\component\config\ComponentPublishConfiguration.py Original: _sts_client = boto3.client("sts") Changed: _sts_client = boto3.client("sts", 'us-east-1')

MikeDombo commented 4 months ago

Hello,

How did you set the AWS_REGION environment variable exactly? The error means that the region was not set.

gagan1469 commented 4 months ago

Hi Mike, The region was provided in the following different ways:

  1. Windows environment variable using "set": AWS_REGION=us-east-1
  2. Set in gdk-config.json

        "publish": {
    "region": "us-east-1",
            "bucket": "ggv2-component-artifacts"
        }

    When that did not work, I also used the --region argument when running component publish

       gdk component publish --region us-east-1 --debug

In both cases, I got the same error.

MikeDombo commented 4 months ago

There is no "--region" option for GDK.

Set the AWS_DEFAULT_REGION environment variable.set AWS_DEFAULT_REGION=us-east-1 if you are using cmd.

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-set

gagan1469 commented 4 months ago

Regarding the --region option, I just followed the gdk component publish --help output:

 gdk component publish --help
  usage: gdk component publish [-h] [-d] [-v] [-b BUCKET] [-r REGION] [-o OPTIONS] {} ...

  Create a new version of a GreengrassV2 component from its built artifacts and recipes.

  positional arguments:
    {}

options:
  -h, --help            show this help message and exit
  -d, --debug           Increase command output to debug level
  -v, --version         show program's version number and exit
  -b BUCKET, --bucket BUCKET
                        Name of the s3 bucket to use for uploading component artifacts. This argument
                        overrides the bucket name provided in the gdk configuration.
  -r REGION, --region REGION
                        Name of the AWS region to use during component creation. This argument overrides
                        the region name provided in the gdk configuration.
  -o OPTIONS, --options OPTIONS
                        Extra configuration options used during component version creation. This argument
                        needs to be a valid json string or file path to a JSON file containing the publish
                        options. This argument overrides the options provided in the gdk configuration.
gagan1469 commented 4 months ago

That said, using AWS_DEFAULT_REGION=us-east-1 environment variable in Windows did the trick. Thanks for the support.