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
You can see that this error is coming from within the SAM Translator: site-packages/samtranslator/translator/arn_generator.py", line 44, in get_partition_name
region_string = region.lower(). The SAM Translator using a Boto3 Session to get the region information (code link). Do you have the region set before running sam validate?
My aws config file looks like this:
[default]
region = eu-west-1
output = json
[profile analyze-sandbox]
role_arn = arn:aws:iam::************:role/devops_extended
source_profile = default
My AWS_PROFILE environment variable is set to analyze-sandbox. When I run sam validate --debug it show the following before getting an error.
2018-05-29 16:03:47 Event needs-retry.iam.ListPolicies: calling handler <botocore.retryhandler.RetryHandler object at 0x7ffa6814af10>
2018-05-29 16:03:47 No retry needed.
2018-05-29 16:03:47 Event after-call.iam.ListPolicies: calling handler <function json_decode_policies at 0x7ffa6870ad70>
2018-05-29 16:03:47 Loading variable profile from environment with value 'analyze-sandbox'.
2018-05-29 16:03:47 Loading variable config_file from defaults.
2018-05-29 16:03:47 Loading variable credentials_file from defaults.
2018-05-29 16:03:47 Loading variable data_path from defaults.
2018-05-29 16:03:47 Loading variable profile from environment with value 'analyze-sandbox'.
2018-05-29 16:03:47 Loading variable region from defaults.
directly followed by the error described in the first post
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.
I was getting the same exact error because I turned off auto-launch of Docker with Windows. I know that running docker is a precursor, but may be a good idea to provide that as a suggestion after checking if a docker process is up with this type of error or prompt to auto start a docker environment? Otherwise, it seems to come out of the blue as it's easy to forget that step while trying to use sam-local (with all of the other potential things that may go wrong).
running into this error, too.
after I set the region under the current profile, it worked.
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.
Looks like a bug.
I'm using named profile and have 'region' configured on it, but 'sam validate --profile X' picks region only from 'default' profile but not from 'X'
@AlexeyPoldeo What version of the CLI are you running? This may have been fixed already but I think I understand what is going on here.
The code link I shared above is where SAM will get the current region (for the default profile) for getting the partition. SAM CLI sets the default profile here.
If you specify both region and profile do things work as expected?
This line may be the problem?
I'm seeing the same issue today on our Jenkins server. We're building out a new pipeline and the server doesn't have either .aws/credentials nor .aws/config as we use EC2 roles and the defaults. SAM runs inside of virtualenv, which, through Python 2.7, uses:
aws-sam-cli==0.6.0
aws-sam-translator==1.6.0
awscli==1.16.15
boto3==1.9.5
botocore==1.12.5
Same issue here. I was not able to find a way to successfully specify the region. Neither through --region, nor through ~/.aws/config, nor AWS_DEFAULT_REGION.
$aws --version
aws-cli/1.16.23 Python/2.7.15rc1 Linux/4.18.8-041808-generic botocore/1.12.13
$ sam --version
SAM CLI, version 0.6.0
Same situation as jhilden above.
Ran into the same issue today, described in #1022 which is closed as it is a duplicate of this.
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
Same error here using the --region option and no region specified in the profile:
$ sam validate -t graphql/template.sam.yaml --region us-east-2 --profile ProfileSansRegion
...line 50, in get_partition_name
region_string = region.lower()
AttributeError: 'NoneType' object has no attribute 'lower'
$ aws --version
aws-cli/1.16.130 Python/3.7.3 Darwin/17.7.0 botocore/1.12.120
$ sam --version
SAM CLI, version 0.17.0
If AWS_DEFAULT_REGION is set to the region, it works.
If AWS_DEFAULT_REGION is set to empty string, it works.
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
samWrapper() {
# https://github.com/awslabs/aws-sam-cli/issues/442
AWS_DEFAULT_REGION=my_static_region sam "$@" --profile my_profile
}
alias samm='samWrapper'
My hacky workaround for now (which I can't wait to remove).
Huge props to @koushinrin and @keroloswilliam.
Like @keroloswilliam, I needed both region and profile defined.
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
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.
Thank you @michaeltarleton, I was having the same problem but it's working after setting up the config file.
I have similar problem.
when I run sam validate --profile my_profile, I got
File "/usr/local/Cellar/aws-sam-cli/0.45.0/libexec/lib/python3.7/site-packages/samtranslator/sdk/parameter.py", line 73, in add_pseudo_parameter_values
if region.startswith("cn-"):
AttributeError: 'NoneType' object has no attribute 'startswith'
it worked after setting config file as @michaeltarleton said, but I hope it works without default setting.
Same issue as well, thanks @michaeltarleton.
SAM Version
SAM CLI, version 0.47.0
Most helpful comment
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-1At the very least, would be nice to add a defensive nil check here to raise a more helpful error.