Repository navigation
Bug: sam local invoke - NoRegionError #7935
Copy link
Copy link
Closed
Labels
need-customer-responseWaiting for customer responseWaiting for customer responsestage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.Automatically applied to new issues and PRs, indicating they haven't been looked at.
Description
Description:
When running this command:
sam local invoke DatabaseBackupLambda --no-event -t ./cdk.out/DatabaseBackupStack.template.json --profile DatabaseBackupRoleI'm receiving this error:
Invoking index.handler (nodejs22.x)
Error: You must specify a region.Steps to reproduce:
- Create custom AWS role and store in local AWS CLI config
- Create a CDK lambda application with TypeScript
- Build the application with
tsc - Run
cdk synth --no-staging - Run
sam local invoke DatabaseBackupLambda --no-event -t ./cdk.out/DatabaseBackupStack.template.json --profile {CUSTOM_AWS_ROLE}
Observed result:
sam local invoke DatabaseBackupLambda --no-event -t ./cdk.out/DatabaseBackupStack.template.json --profile DatabaseBackupRole --debug <region:us-east-1>
2025-03-15 22:17:45,200 | No config file found in this directory.
2025-03-15 22:17:45,201 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/samconfig.toml'
2025-03-15 22:17:45,202 | Config file location: /Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/samconfig.toml
2025-03-15 22:17:45,202 | Config file '/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/samconfig.toml' does not exist
2025-03-15 22:17:45,211 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/samconfig.toml'
2025-03-15 22:17:45,211 | Using config file: samconfig.toml, config environment: default
2025-03-15 22:17:45,211 | Expand command line arguments to:
2025-03-15 22:17:45,212 | --template_file=/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/DatabaseBackupStack.template.json --function_logical_id=DatabaseBackupLambda --layer_cache_basedir=/Users/kentonduprey/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2025-03-15 22:17:45,212 | local invoke command is called
2025-03-15 22:17:46,343 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2025-03-15 22:17:46,376 | CDK Path for resource LambdaExecutionRoleD5C26073 is ['DatabaseBackupStack', 'LambdaExecutionRole', 'Resource']
2025-03-15 22:17:46,377 | CDK Path for resource LambdaExecutionRoleDefaultPolicy6D69732F is ['DatabaseBackupStack', 'LambdaExecutionRole', 'DefaultPolicy', 'Resource']
2025-03-15 22:17:46,377 | CDK Path for resource DatabaseBackupLambdaE40A695F is ['DatabaseBackupStack', 'DatabaseBackupLambda', 'Resource']
2025-03-15 22:17:46,378 | CDK Path for resource DatabaseBackupLambdainlinePolicyAddedToExecutionRole0E74F90B7 is ['DatabaseBackupStack', 'DatabaseBackupLambda', 'inlinePolicyAddedToExecutionRole-0', 'Resource']
2025-03-15 22:17:46,379 | CDK Path for resource ScheduleRuleDA5BD877 is ['DatabaseBackupStack', 'ScheduleRule', 'Resource']
2025-03-15 22:17:46,379 | CDK Path for resource ScheduleRuleAllowEventRuleDatabaseBackupStackDatabaseBackupLambda51AC99E2548B0654 is ['DatabaseBackupStack', 'ScheduleRule', 'AllowEventRuleDatabaseBackupStackDatabaseBackupLambda51AC99E2']
2025-03-15 22:17:46,380 | CDK Path for resource CDKMetadata is ['DatabaseBackupStack', 'CDKMetadata', 'Default']
2025-03-15 22:17:46,381 | 0 stacks found in the template
2025-03-15 22:17:46,381 | Collected default values for parameters: {'BootstrapVersion': '/cdk-bootstrap/hnb659fds/version'}
2025-03-15 22:17:46,393 | CDK Path for resource LambdaExecutionRoleD5C26073 is ['DatabaseBackupStack', 'LambdaExecutionRole', 'Resource']
2025-03-15 22:17:46,394 | CDK Path for resource LambdaExecutionRoleDefaultPolicy6D69732F is ['DatabaseBackupStack', 'LambdaExecutionRole', 'DefaultPolicy', 'Resource']
2025-03-15 22:17:46,394 | CDK Path for resource DatabaseBackupLambdaE40A695F is ['DatabaseBackupStack', 'DatabaseBackupLambda', 'Resource']
2025-03-15 22:17:46,395 | CDK Path for resource DatabaseBackupLambdainlinePolicyAddedToExecutionRole0E74F90B7 is ['DatabaseBackupStack', 'DatabaseBackupLambda', 'inlinePolicyAddedToExecutionRole-0', 'Resource']
2025-03-15 22:17:46,395 | CDK Path for resource ScheduleRuleDA5BD877 is ['DatabaseBackupStack', 'ScheduleRule', 'Resource']
2025-03-15 22:17:46,395 | CDK Path for resource ScheduleRuleAllowEventRuleDatabaseBackupStackDatabaseBackupLambda51AC99E2548B0654 is ['DatabaseBackupStack', 'ScheduleRule', 'AllowEventRuleDatabaseBackupStackDatabaseBackupLambda51AC99E2']
2025-03-15 22:17:46,396 | CDK Path for resource CDKMetadata is ['DatabaseBackupStack', 'CDKMetadata', 'Default']
2025-03-15 22:17:46,397 | 7 resources found in the stack
2025-03-15 22:17:46,397 | Found Lambda function with name='DatabaseBackupLambdaE40A695F' and CodeUri='asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c'
2025-03-15 22:17:46,397 | --base-dir is not presented, adjusting uri asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c relative to /Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/DatabaseBackupStack.template.json
2025-03-15 22:17:46,398 | Skip building pre-built function: DatabaseBackupLambda
2025-03-15 22:17:46,434 | Found one Lambda function with name 'DatabaseBackupLambda'
2025-03-15 22:17:46,434 | Invoking index.handler (nodejs22.x)
2025-03-15 22:17:46,434 | Loading AWS credentials from session with profile 'DatabaseBackupRole'
2025-03-15 22:17:47,070 | Resolving code path. Cwd=/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out, CodeUri=/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c
2025-03-15 22:17:47,072 | Resolved absolute path to code is /Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c
2025-03-15 22:17:47,074 | Resolving code path. Cwd=/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out, CodeUri=/Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c
2025-03-15 22:17:47,075 | Resolved real code path to /Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c
2025-03-15 22:17:47,077 | Code /Users/kentonduprey/GitHub/how/how-apps/aws/db-backup/cdk.out/asset.d396c88537347ad799f49a5abf0cd17135387a9a39fa40bbbfbe8995e43e747c is not a zip/jar file
2025-03-15 22:17:47,125 | Cleaning all decompressed code dirs
2025-03-15 22:17:47,126 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-03-15 22:17:47,150 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2025-03-15 22:17:47,151 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '73d365a5-ebc9-4667-90bd-71cea6060fb4', 'installationId': '7865405b-e166-444a-834e-9e7b62adccee', 'sessionId': 'e2096d14-3997-47ba-b283-c63d60e633cf', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion': '1.135.0', 'awsProfileProvided': True,
'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CDK', 'gitOrigin': None, 'projectName': 'ae250ecae5999e5522cf55577af90922668f66be1765f1214e3f5a12b1cfbb25', 'initialCommit': None}, 'duration': 1914, 'exitReason': 'NoRegionError', 'exitCode': 255}}]}
2025-03-15 22:17:47,151 | Unable to find Click Context for getting session_id.
2025-03-15 22:17:47,153 | Sending Telemetry: {'metrics': [{'events': {'requestId': '65aa7ef4-850d-425d-be40-4e551f65eae5', 'installationId': '7865405b-e166-444a-834e-9e7b62adccee', 'sessionId': 'e2096d14-3997-47ba-b283-c63d60e633cf', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion': '1.135.0', 'commandName': 'sam local invoke',
'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '5104ee2858b146ea8c439587ef54c786', 'time_stamp': '2025-03-16 02:17:45.202', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '905b0dda134942eeb1c98bde872c369d', 'time_stamp': '2025-03-16
02:17:45.211', 'exception_name': None}, {'event_name': 'UsedFeature', 'event_value': 'CDK', 'thread_id': '89b32f180d3143058289394e35cb10b2', 'time_stamp': '2025-03-16 02:17:47.126', 'exception_name': None}]}}}]}
2025-03-15 22:17:47,423 | Telemetry response: 200
2025-03-15 22:17:47,426 | Telemetry response: 200
Error: You must specify a region.
Traceback:
File "click/core.py", line 1078, in main
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1434, in invoke
File "click/core.py", line 783, in invoke
File "samcli/cli/cli_config_file.py", line 347, in wrapper
File "click/decorators.py", line 92, in new_func
File "click/core.py", line 783, in invoke
File "samcli/lib/telemetry/metric.py", line 185, in wrapped
File "samcli/lib/telemetry/metric.py", line 150, in wrapped
File "samcli/lib/utils/version_checker.py", line 43, in wrapped
File "samcli/cli/main.py", line 95, in wrapper
File "samcli/commands/local/invoke/cli.py", line 126, in cli
File "samcli/commands/local/invoke/cli.py", line 235, in do_cli
File "samcli/commands/local/lib/local_lambda.py", line 169, in invoke
File "samcli/lib/telemetry/metric.py", line 325, in wrapped_func
File "samcli/local/lambdafn/runtime.py", line 229, in invoke
File "samcli/local/lambdafn/runtime.py", line 100, in create
File "samcli/local/docker/lambda_container.py", line 106, in __init__
File "samcli/local/docker/lambda_container.py", line 261, in _get_image
File "samcli/local/docker/lambda_image.py", line 203, in build
File "samcli/local/layers/layer_downloader.py", line 77, in download_all
File "samcli/local/layers/layer_downloader.py", line 111, in download
File "samcli/local/layers/layer_downloader.py", line 141, in _fetch_layer_uri
File "samcli/local/layers/layer_downloader.py", line 43, in lambda_client
File "boto3/__init__.py", line 92, in client
File "boto3/session.py", line 297, in client
File "botocore/session.py", line 997, in create_client
File "botocore/client.py", line 165, in create_client
File "botocore/client.py", line 524, in _get_client_args
File "botocore/args.py", line 101, in get_client_args
File "botocore/args.py", line 220, in compute_client_args
File "botocore/args.py", line 374, in _compute_endpoint_config
File "botocore/args.py", line 479, in _resolve_endpoint
File "botocore/client.py", line 629, in resolve
File "botocore/regions.py", line 230, in construct_endpoint
File "botocore/regions.py", line 278, in _endpoint_for_partition
An unexpected error was encountered while executing "sam local invoke".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20local%20invoke%20-%20NoRegionError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20local%20invoke%20-%20NoRegionErrorExpected result:
I expected my function to run and return a 200 success response, or at the least start it's execution and possibly error within the function runtime, but not during SAM initialisation.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --info <region:us-east-1>
{
"version": "1.135.0",
"system": {
"python": "3.11.10",
"os": "macOS-15.3.2-arm64-arm-64bit"
},
"additional_dependencies": {
"docker_engine": "27.5.1",
"aws_cdk": "2.1004.0 (build f0ad96e)",
"terraform": "1.5.7"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
need-customer-responseWaiting for customer responseWaiting for customer responsestage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.Automatically applied to new issues and PRs, indicating they haven't been looked at.
Activity
Aiden-Gaines commentedon Mar 21, 2025
+1 I've also run into this same issue when using the Lambda Development Kit from AWS Toolkit for IntelliJ.
roger-zhangg commentedon Mar 21, 2025
Seems like you don't have a region in your
~/.aws/configCould you help to confirm if this is true? Cause some of the local invoke features (like downloading layer/ initiating botocore/ sdks requires region.)Aiden-Gaines commentedon Mar 21, 2025
I have
region=us-west-2listed under both my[DEFAULT]credentials and the profile I am using.roger-zhangg commentedon Mar 21, 2025
'awsProfileProvided': True,'debugFlagProvided': True, 'region': ''seems telling it didn't pick up the region. Could you test basic commends likeaws lambda list-functionsto see if that works?Aiden-Gaines commentedon Mar 21, 2025
It seems that
aws configureactually fixed my problem. Thanks!kduprey commentedon Mar 22, 2025
@roger-zhangg - Currently my
~/.aws/configfile does have the region specified.Let me know if you need more info.
vicheey commentedon Mar 28, 2025
@kduprey ,
Can you try adding the region for DatabaseBackupRole specifically?
aws configure --profile DatabaseBackupRolekduprey commentedon May 5, 2025
Hi @vicheey,
I've tried that as well and this does not resolve the issue.
tinawangtw commentedon Jan 30, 2026
Hi @kduprey, do you still have this issue ongoing? Or can you try to run a simple aws command like
aws lambda list-functionsto see it picks your default region?seshubaws commentedon Mar 16, 2026
Closing due to no further customer response. Reopen if necessary
github-actions commentedon Mar 16, 2026
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.