Unable to debug locally after 1.6.2 update
Description
After updating to AWS SAM CLI 1.6.2 today, I am no longer able to debug Python API Lambdas locally using sam local start-api.
sam local start-api... is being executed from a script, and I have added docker-credential-desktop -h to that same script to see if it is available, which it seems to be based on the output below.
I am using conda to manage Python modules, and I have removed and re-created that environment. No change in behavior.
I have removed and re-installed Docker Desktop. Again, no change in behavior.
The only other thing that was changed was updating AWS SAM CLI to 1.6.2 earlier in the day before this problem started.
Steps to reproduce
Build API locally
Run script with sam local start-api ...
Observed result
Process starts normally:
> Executing task: local/debug_start.sh admin <
Usage:
docker-credential-desktop [flags]
docker-credential-desktop [command]
Available Commands:
erase Removes a set of credentials from the store
get Retrieves credentials from the store
help Help about any command
list Lists the credentials in the store
move Move credentials from one store to another
store Adds a set of credentials to the store
version Display the version of the credentials helper protocol
Flags:
-h, --help help for docker-credential-desktop
Use "docker-credential-desktop [command] --help" for more information about a command.
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
local start-api command is called
Collected default values for parameters: {}
Unable to resolve property UserPoolArn: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${CognitoStackName}-${ApiName}UserPoolArn')]))]). Leaving as is.
Unable to resolve property DB_NAME: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseName')]))]). Leaving as is.
Unable to resolve property DB_CLUSTER_ARN: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseClusterArn')]))]). Leaving as is.
Unable to resolve property DB_CRED_SECRETS_STORE_ARN: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseSecretArn')]))]). Leaving as is.
Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseClusterArn')]))]). Leaving as is.
Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseSecretArn')]))]). Leaving as is.
3 resources found in the template
Found Serverless function with name='ApiDispatcher' and CodeUri='ApiDispatcher'
Collected default values for parameters: {}
Unable to resolve property UserPoolArn: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${CognitoStackName}-${ApiName}UserPoolArn')]))]). Leaving as is.
Unable to resolve property DB_NAME: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseName')]))]). Leaving as is.
Unable to resolve property DB_CLUSTER_ARN: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseClusterArn')]))]). Leaving as is.
Unable to resolve property DB_CRED_SECRETS_STORE_ARN: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseSecretArn')]))]). Leaving as is.
Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseClusterArn')]))]). Leaving as is.
Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', OrderedDict([('Fn::Sub', '${DatabaseStackName}-DatabaseSecretArn')]))]). Leaving as is.
3 resources found in the template
Detected Inline Swagger definition
Lambda function integration not found in Swagger document at path='/{domain}' method='options'
Lambda function integration not found in Swagger document at path='/{domain}' method='x-amazon-apigateway-any-method'
Lambda function integration not found in Swagger document at path='/{domain}/{id}' method='options'
Lambda function integration not found in Swagger document at path='/{domain}/{id}' method='x-amazon-apigateway-any-method'
Found '0' APIs in resource 'BikePumpApi'
Found '4' API Events in Serverless function with name 'ApiDispatcher'
Removed duplicates from '4' Explicit APIs and '0' Implicit APIs to produce '2' APIs
2 APIs found in the template
Mounting ApiDispatcher at http://127.0.0.1:2222/{domain} [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
Mounting ApiDispatcher at http://127.0.0.1:2222/{domain}/{id} [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
Localhost server is starting up. Multi-threading = False
* Tip: There are .env files present. Do "pip install python-dotenv" to use them.
2020-10-27 18:17:22 * Running on http://127.0.0.1:2222/ (Press CTRL+C to quit)
source /Users/jamie/miniconda3/envs/BikePump/bin/activate
But the following errors are reported when an API call is issued:
Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/{domain}", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/{domain}", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "EnvType-ApiVersion", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/{domain}", "protocol": "HTTP/1.1", "domainName": "localhost:2222", "requestTimeEpoch": 1603840642, "requestTime": "27/Oct/2020:23:17:22 +0000"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "vscode-restclient", "Authorization": "Bearer eyJraWQiOiJUQlBONnhzdUlJeXl4UVBsdDRuU1JOOVFLSWlcL0diNE5aMVpHeVN2OWJJMD0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI1YmU0OTU4MC1mMzM0LTQ4NmEtODU2Mi0wZmJiNjgzMmQ3NmMiLCJhdWQiOiI3c3JidTlpNmhpYTg5aGNzanNzdDgxdWszYSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJldmVudF9pZCI6IjRkNWRmOWYwLTM0ZjYtNGQzOS1iZmU3LWUxOGM4ZTc0MjE3NCIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNjAzODM0NzgyLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9mQ3RRRVR2MWsiLCJjb2duaXRvOnVzZXJuYW1lIjoiNWJlNDk1ODAtZjMzNC00ODZhLTg1NjItMGZiYjY4MzJkNzZjIiwiZXhwIjoxNjAzODM4MzgyLCJpYXQiOjE2MDM4MzQ3ODIsImVtYWlsIjoidGVzdHVzZXJAZ3JpZmZ5LmNvbSJ9.sGoXP6UZioQPaJnugJLAoanNkSMENOt9_MAK8BFSPLLqbgHWxj2No4YHnAUGI0nfMmp83CFYrZ7AIbC3_WUl7aP71zSHIdJJqTnMNrOj6dASV-Mklz4H2rQCXuJv4SGtY1vwP5Pb5xtoUM2zsWoc8O_J7RBEEQq4oh115on2PCKu9CRYquCLrf0azsvdcl7IjEwggrg0BrOhEE-N4jspdj8ZJl0JwVxbQAQB1Ek81nmBdI6l6GeE2IDtNTxXmRDooPIBX0TJ6FnKf5fe1g-v9CQKFRedbtjesavumlT8kDEi9PsPOM9d-6ocBWRbQVqy5M6dhfMbEcgor7Bug2-F0A", "Accept-Encoding": "gzip, deflate", "Host": "localhost:2222", "Connection": "close", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "2222"}, "multiValueHeaders": {"User-Agent": ["vscode-restclient"], "Authorization": ["Bearer eyJraWQiOiJUQlBONnhzdUlJeXl4UVBsdDRuU1JOOVFLSWlcL0diNE5aMVpHeVN2OWJJMD0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI1YmU0OTU4MC1mMzM0LTQ4NmEtODU2Mi0wZmJiNjgzMmQ3NmMiLCJhdWQiOiI3c3JidTlpNmhpYTg5aGNzanNzdDgxdWszYSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJldmVudF9pZCI6IjRkNWRmOWYwLTM0ZjYtNGQzOS1iZmU3LWUxOGM4ZTc0MjE3NCIsInRva2VuX3VzZSI6ImlkIiwiYXV0aF90aW1lIjoxNjAzODM0NzgyLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9mQ3RRRVR2MWsiLCJjb2duaXRvOnVzZXJuYW1lIjoiNWJlNDk1ODAtZjMzNC00ODZhLTg1NjItMGZiYjY4MzJkNzZjIiwiZXhwIjoxNjAzODM4MzgyLCJpYXQiOjE2MDM4MzQ3ODIsImVtYWlsIjoidGVzdHVzZXJAZ3JpZmZ5LmNvbSJ9.sGoXP6UZioQPaJnugJLAoanNkSMENOt9_MAK8BFSPLLqbgHWxj2No4YHnAUGI0nfMmp83CFYrZ7AIbC3_WUl7aP71zSHIdJJqTnMNrOj6dASV-Mklz4H2rQCXuJv4SGtY1vwP5Pb5xtoUM2zsWoc8O_J7RBEEQq4oh115on2PCKu9CRYquCLrf0azsvdcl7IjEwggrg0BrOhEE-N4jspdj8ZJl0JwVxbQAQB1Ek81nmBdI6l6GeE2IDtNTxXmRDooPIBX0TJ6FnKf5fe1g-v9CQKFRedbtjesavumlT8kDEi9PsPOM9d-6ocBWRbQVqy5M6dhfMbEcgor7Bug2-F0A"], "Accept-Encoding": ["gzip, deflate"], "Host": ["localhost:2222"], "Connection": ["close"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["2222"]}, "pathParameters": {"domain": "testTask"}, "stageVariables": null, "path": "/testTask", "isBase64Encoded": false}
Found one Lambda function with name 'ApiDispatcher'
Invoking bikepump_admin_api.api_dispatcher (python3.8)
Environment variables overrides data is in CloudFormation parameter file format
Loading AWS credentials from session with profile 'None'
Resolving code path. Cwd=/Users/jamie/Projects/BikePumpApi/.aws-sam-admin/build, CodeUri=ApiDispatcher
Resolved absolute path to code is /Users/jamie/Projects/BikePumpApi/.aws-sam-admin/build/ApiDispatcher
Code /Users/jamie/Projects/BikePumpApi/.aws-sam-admin/build/ApiDispatcher is not a zip/jar file
Image was not found.
Building image...2020-10-27 18:18:58 Exception on /testTask [GET]
Traceback (most recent call last):
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/app.py", line 2317, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/app.py", line 1840, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/app.py", line 1743, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/app.py", line 1838, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/flask/app.py", line 1824, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/apigw/local_apigw_service.py", line 203, in _request_handler
self.lambda_runner.invoke(route.function_name, event, stdout=stdout_stream_writer, stderr=self.stderr)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 103, in invoke
self.local_runtime.invoke(config, event, debug_context=self.debug_context, stdout=stdout, stderr=stderr)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 70, in invoke
container = LambdaContainer(
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 73, in __init__
image = LambdaContainer._get_image(image_builder, runtime, layers, debug_options)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/docker/lambda_container.py", line 179, in _get_image
return image_builder.build(runtime, layers, is_debug)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 132, in build
self._build_image(base_image, image_tag, downloaded_layers, is_debug_go, stream=stream_writer)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/samcli/local/docker/lambda_image.py", line 221, in _build_image
resp_stream = self.docker_client.api.build(
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/docker/api/build.py", line 261, in build
self._set_auth_headers(headers)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/docker/api/build.py", line 308, in _set_auth_headers
auth_data = self._auth_configs.get_all_credentials()
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/docker/auth.py", line 301, in get_all_credentials
store = self._get_store_instance(self.creds_store)
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/docker/auth.py", line 286, in _get_store_instance
self._stores[name] = credentials.Store(
File "/usr/local/Cellar/aws-sam-cli/1.6.2/libexec/lib/python3.8/site-packages/docker/credentials/store.py", line 23, in __init__
raise errors.InitializationError(
docker.credentials.errors.InitializationError: docker-credential-desktop not installed or not available in PATH
2020-10-27 18:18:58 127.0.0.1 - - [27/Oct/2020 18:18:58] "GET /testTask HTTP/1.1" 502 -
Expected result
Expect to be able to successfully execute and debug API calls locally.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
macOS 10.15.7 Python 3.8 AWS SAM CLI 1.6.2 Conda 4.8.5 Docker Desktop 2.4.0.0 (48506)
Hi @jamie-burks ,
I tried to re-produce the issue on my local environment (with SAM CLI 1.6.2 and Hello World app for Python3.8) and I was able to debug the application.
Can you provide an example that we can re-produce locally? That will help us a lot.
Thanks
Well, I'm not sure how. All I know is local debug started crashing when I updated to the latest version. I'm not running in a container or VM, straight out of the box macOS. Here's the script I'm using to start the debugger locally. Nothing very complex. The call to the config_api_$1.sh script just sets environment variables based on which API I'm debugging. This is the script where I added the docker-credential-desktop -h command to make sure it was on the PATH, which it is. I typically launch this from VSCode, but I get the same results when it's launched from the command line.
Is there any other debug output or anything else that might help pinpoint the problem?
#!/bin/bash
#===============================================================================
# Script to start local API for debugger attach
#===============================================================================
set -e
function error() {
echo "Error: $1"
exit -1
}
[[ -n "$1" ]] || error "Missing API name (e.g. mobile, ads, admin)"
. "./deploy_scripts/config_api_$1.sh"
sam local start-api --port $api_debug_port --debug-port 5890 \
--env-vars local/env_vars_local.json \
--template .aws-sam-$1/build/template.yaml \
--parameter-overrides \
ApiName="$1"
Well I can report that through no overt action of my own, the problem reported above has gone away. I have absolutely no idea how or why. I started going through setting up the HelloWorld sample app in a separate directory, and of course it worked. Then I went back to my code in its directory with no changes made and it just worked. Not sure if that kickstarted something or what, but at least the roadblock is gone. Appreciate you looking into this.
Happy to hear that problem is resolved at the moment. Please open this issue (or a new one) if the problem still exists.
I'd like to reopen this and add some new information. This same problem came back today. The last time it mysteriously went away, I had set up one of the sample AWS SAM apps to try to reproduce it in a simple sandbox. After the problem came back today, I did the same thing and lo and behold it went away again. I'm not sure how there would be any interaction between two completely separate projects and conda environments unless maybe it were something in Docker, one of the VMs, or SAM. All I'm doing in the sample app is following the README - running sam init then sam build --use-container then sam local invoke HelloWorldFunction --event events/event.json. I do not use --use-container to build my SAM apps, but I don't think that would have anything to do with how local invoke or local start-api behave. At least it seems I have a reliable "fix" for this if it pops back up, but what could possibly cause something like this?