aws-sam-cli: AttributeError in arn_generator.py

Description: Trying to run the command sam validate and get an error that is somewhat hard to understand. May this be related to python version? (Currently 2.7.12) or something else?

Observed result:

2018-05-29 14:05:38 Starting new HTTPS connection (1): sts.amazonaws.com
2018-05-29 14:05:39 Starting new HTTPS connection (1): iam.amazonaws.com
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 11, in <module>
    sys.exit(cli())
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/home/kansuler/.local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/samcli/commands/validate/validate.py", line 28, in cli
    do_cli(ctx, template)  # pragma: no cover
  File "/usr/local/lib/python2.7/dist-packages/samcli/commands/validate/validate.py", line 42, in do_cli
    validator.is_valid()
  File "/usr/local/lib/python2.7/dist-packages/samcli/commands/validate/lib/sam_template_validator.py", line 60, in is_valid
    parameter_values={})
  File "/home/kansuler/.local/lib/python2.7/site-packages/samtranslator/translator/translator.py", line 57, in translate
    deployment_preference_collection = DeploymentPreferenceCollection()
  File "/home/kansuler/.local/lib/python2.7/site-packages/samtranslator/model/preferences/deployment_preference_collection.py", line 30, in __init__
    self.codedeploy_iam_role = self._codedeploy_iam_role()
  File "/home/kansuler/.local/lib/python2.7/site-packages/samtranslator/model/preferences/deployment_preference_collection.py", line 89, in _codedeploy_iam_role
    ArnGenerator.generate_aws_managed_policy_arn('service-role/AWSCodeDeployRoleForLambda')
  File "/home/kansuler/.local/lib/python2.7/site-packages/samtranslator/translator/arn_generator.py", line 22, in generate_aws_managed_policy_arn
    return 'arn:{}:iam::aws:policy/{}'.format(ArnGenerator.get_partition_name(),
  File "/home/kansuler/.local/lib/python2.7/site-packages/samtranslator/translator/arn_generator.py", line 44, in get_partition_name
    region_string = region.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

Expected result: A proper error message

Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Ubuntu 16.04.4 on WSL

Output of sam --version: SAM CLI, version 0.3.0

Optional Debug logs:

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I am a new user following the hello world tutorial linked from the README and hit this issue. I don’t really understand all the AWS terminology yet, but the following (suggested in the code linked above) fixed for me:

export AWS_DEFAULT_REGION=us-west-1

At the very least, would be nice to add a defensive nil check here to raise a more helpful error.

running into this error, too. after I set the region under the current profile, it worked.

I fixed this by adding a default configuration to my ~/.aws/config file:

[default]
region = us-west-2

I did not need to configure environment variables.

Same issue here worked only with AWS_DEFAULT_REGION set before running the command like so

AWS_DEFAULT_REGION=<REGION> sam validate -t template.yaml --profile <PROFILE>

sam --version SAM CLI, version 0.19.0

aws --version aws-cli/1.16.225 Python/3.6.8 Linux/5.0.0-23-generic botocore/1.12.215

Same here, it’s still a bug:

$ sam validate --region eu-west-1

leads to:

[...]
    region_string = region.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

Versions:

$ aws --version
aws-cli/1.16.70 Python/3.7.3 Darwin/18.5.0 botocore/1.12.60
$ sam --version
SAM CLI, version 0.14.2

Thank you @michaeltarleton, I was having the same problem but it’s working after setting up the config file.

Same problem but it was happening on my Windows environment from within Visual Studio Code. For posterity the fix was basically the same except for the syntax.

Set-Item -path env:AWS_DEFAULT_REGION -value us-east-1

This was released in v1.23.0

Closing.

hmm… It looks like it is picking it up. Without actually running the cli with breakpoints, I can’t tell if this is an issue within SAM CLI or the SAM Translator. For now, marking this as a bug but will need to do a deeper dive before knowing what is going on here.