Description:
Steps to reproduce the issue:
Observed result:
```Traceback (most recent call last):
File "/usr/local/bin/sam", line 11, in
load_entry_point('aws-sam-cli==0.47.0', 'console_scripts', 'sam')()
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(args, *kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, *ctx.params)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(args, *kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, *kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(args, *kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 96, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 62, in wrapped
return_value = func(args, *kwargs)
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samcli/commands/validate/validate.py", line 27, in cli
do_cli(ctx, template_file) # pragma: no cover
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samcli/commands/validate/validate.py", line 47, in do_cli
validator.is_valid()
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 60, in is_valid
template = sam_translator.translate(sam_template=self.sam_template, parameter_values={})
File "/usr/local/Cellar/aws-sam-cli/0.47.0/libexec/lib/python3.7/site-packages/samtranslator/translator/translator.py", line 88, in translate
sam_parameter_values.add_pseudo_parameter_values()
File "/usr/local/Cellar/aws-sam-cli/0.47.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'
**Expected result:**
The function to to tell me whether or not my yml file is valid.
**Template.yml**
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
recipe-monster
Sample SAM Template for recipe-monster
Globals:
Function:
Timeout: 3
Resources:
RecipeMonsterFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: src/
Handler: app.lambda_handler
Runtime: python3.8
Events:
RecipeMonster:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /recipes
Method: POST
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
RecipeMonsterApi:
Description: "API Gateway endpoint URL for Prod stage for Recipe Monster function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
RecipeMonsterFunction:
Description: "Recipe Monster Lambda Function ARN"
Value: !GetAtt RecipeMonsterFunction.Arn
RecipeMonsterFunctionIamRole:
Description: "Implicit IAM Role created for Recipe Monster function"
Value: !GetAtt RecipeMonsterFunctionRole.Arn
```
@brukhabtu SAM expects a region to be set in the boto3 or aws configuration in order to do validation. If you run aws configure and set a region, this validate call should work.
agree with @keetonian comment, but will keep this open so that the an appropriate error message is thrown instead.
@brukhabtu SAM expects a region to be set in the boto3 or aws configuration in order to do validation. If you run
aws configureand set a region, this validate call should work.
I had the exact same problem with the sam cli even though I already had region=us-east-1 set in my ~/.aws/credentials and the aws cli was able to reach other services on AWS. I also tried adding --region us-east-1 at the end of sam validate --profile MyProfile.
I'm on SAM CLI, version 0.49.0
UPDATE: When I ran export AWS_DEFAULT_REGION=us-east-1 before re-running sam validate, the error went away.
Same issue, and same hacky fix that @ystoneman describes let me continue working.
Running: sam validate --profile personal
Get the same error as the OP shared
SAM CLI, version 0.51.0
I have no default profile, using a named profile which has region configured in my config file and otherwise works just fine:
[personal]
region = eu-west-2
It seems that the syntax in .aws/config is a little quirky. I've got same error as everyone else with:
[home]
region = us-west-2
but the it worked with:
[profile home]
region = us-west-2
This is different from the convention in .aws/credentials, where "profile" is not used.
In my case was set the file .aws/config to
[default]
region = ap-southeast-2
and then sam validate worked
SAM CLI version 1.2.0
First error in the output for me was on line 33 instead of 11 as stated in OPs post.
Can confirm the region not being set was also my issue. Also, I keep multiple profiles on my box.
What does NOT work is setting export AWS_REGION=<your region> even after running export AWS_PROFILE=<your profile>
How to fix w/ multiple profiles...
In ~/.aws/config:
[profile yourProfileName]
region = your-region-here
output = json (this is optional of course)
[profile otherProfile]
...
In ~/.aws/credentials:
[yourProfileName] <-- note w/o the word "profile"
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
[otherProfile]
...
Then run export AWS_PROFILE=yourProfileName
Lastly, you can finally run sam validate
For LOLz, I just started trying to learn SAM-CLI _just_ after running brew upgrade which updated a ton of stuff, including Python ... so to see python errors start to roll around right after ... (╯ಠ_ಠ)╯︵ ┻━┻
@brukhabtu SAM expects a region to be set in the boto3 or aws configuration in order to do validation. If you run
aws configureand set a region, this validate call should work.I had the exact same problem with the sam cli even though I already had
region=us-east-1set in my~/.aws/credentialsand the aws cli was able to reach other services on AWS. I also tried adding--region us-east-1at the end ofsam validate --profile MyProfile.I'm on SAM CLI, version 0.49.0
UPDATE: When I ran
export AWS_DEFAULT_REGION=us-east-1before re-runningsam validate, the error went away.
I had the exact same problem. I have multiple profiles that defined in .aws/config and .aws/credentials. The weird thing is, it worked pretty well on my local macbook while I have the same versions of SAM CLI on my macbook and my gitlab server. I feel sam failed to retrieve the region value from the --region parameter. Anyways, export AWS_DEFAULT_REGION=$var_region
I am on 4.14.186-146.268.amzn2.x86_64 and SAM CLI, version 1.6.2
sam version 1.15.0, AWS CLI version aws-cli/2.1.13 Python/3.7.4 Darwin/19.6.0 exe/x86_64 prompt/off
this didn't worked
sam validate -t template.yaml --profile private_user1 --region eu-central-1 --debug
but when I export AWS_DEFAULT_REGION=eu-central-1 worked.
setting it from aws config --profile private_user1 also didn't help
Most helpful comment
I had the exact same problem with the sam cli even though I already had
region=us-east-1set in my~/.aws/credentialsand the aws cli was able to reach other services on AWS. I also tried adding--region us-east-1at the end ofsam validate --profile MyProfile.I'm on SAM CLI, version 0.49.0
UPDATE: When I ran
export AWS_DEFAULT_REGION=us-east-1before re-runningsam validate, the error went away.