Aws-sam-cli: Hello World example not working due to server error

Created on 25 Jan 2019  路  9Comments  路  Source: aws/aws-sam-cli

Description

I just downloaded docker desktop and aws-sam-cli and tried to execute hello world example but got "500 Server Error: Internal Server Error for url: http+docker://localnpipe/v1.35/containers/create" error. There were no modifications done by me just downloaded and installed docker and aws sam cli. Below are the versions of dependencies on my system:

D:\sam-app>python --version
Python 3.7.0

D:\sam-app>sam --version
SAM CLI, version 0.10.0

D:\sam-app>aws --version
aws-cli/1.15.69 Python/3.7.0 Windows/10 botocore/1.10.68

D:\sam-app>node --version
v10.7.0

Steps to reproduce

  1. Download and install docker desktop
  2. Download and install aws-sam-cli
  3. Restart PC
  4. Start Docker Desktop in admin mode
  5. Open CMD prompt in admin mode
  6. Execute below commands

D:>sam init --runtime nodejs8.10
D:>cd sam-app
D:\sam-app>sam build
D:\sam-app>sam local start-api --debug

Then open http://localhost:3000/hello in browser

Observed result

{
message: "Internal server error"
}

D:>sam init --runtime nodejs8.10
[+] Initializing project structure...
[SUCCESS] - Read sam-app/README.md for further instructions on how to proceed
[*] Project initialization is now complete

D:\sam-app>sam build
2019-01-25 14:07:37 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-25 14:07:40 Building resource 'HelloWorldFunction'
2019-01-25 14:07:40 'nodejs' runtime has not been validated!
2019-01-25 14:07:40 Running NodejsNpmBuilder:NpmPack
2019-01-25 14:07:57 Running NodejsNpmBuilder:CopySource
2019-01-25 14:07:57 Running NodejsNpmBuilder:NpmInstall

Build Succeeded

Built Artifacts : .aws-sam\build
Built Template : .aws-sam\build\template.yaml

D:\sam-app>sam local start-api --debug
2019-01-25 14:08:48 Using SAM Template at D:\sam-app.aws-sam\build\template.yaml
2019-01-25 14:08:48 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-25 14:08:48 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-25 14:08:48 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-25 14:08:48 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-25 14:08:48 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-25 14:08:48 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-25 14:08:48 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-25 14:08:48 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-25 14:08:48 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section
2019-01-25 14:08:48 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-25 14:08:48 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section
2019-01-25 14:08:48 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-01-25 14:08:48 Changing event name from before-call.apigateway to before-call.api-gateway
2019-01-25 14:08:48 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-01-25 14:08:48 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-01-25 14:08:48 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-01-25 14:08:48 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-01-25 14:08:48 Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section
2019-01-25 14:08:48 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-01-25 14:08:48 Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section
2019-01-25 14:08:48 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-01-25 14:08:48 Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section
2019-01-25 14:08:48 local start-api command is called
2019-01-25 14:08:49 Looking for credentials via: env
2019-01-25 14:08:49 Looking for credentials via: assume-role
2019-01-25 14:08:49 Looking for credentials via: shared-credentials-file
2019-01-25 14:08:49 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-25 14:08:49 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\endpoints.json
2019-01-25 14:08:49 Event choose-service-name: calling handler
2019-01-25 14:08:51 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\serverlessrepo\2017-09-08\service-2.json
2019-01-25 14:08:51 Event creating-client-class.serverlessapplicationrepository: calling handler
2019-01-25 14:08:51 The s3 config key is not a dictionary type, ignoring its value of: None
2019-01-25 14:08:51 Setting serverlessrepo timeout as (60, 60)
2019-01-25 14:08:51 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data_retry.json
2019-01-25 14:08:51 Registering retry handlers for service: serverlessrepo
2019-01-25 14:08:51 No Parameters detected in the template
2019-01-25 14:08:51 2 resources found in the template
2019-01-25 14:08:51 Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2019-01-25 14:08:51 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:08:51 No config file found
2019-01-25 14:08:51 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:08:51 No config file found
2019-01-25 14:08:51 http://localhost:None "GET /v1.35/_ping HTTP/1.1" 200 2
2019-01-25 14:08:51 Event choose-service-name: calling handler
2019-01-25 14:08:51 Event creating-client-class.serverlessapplicationrepository: calling handler
2019-01-25 14:08:51 The s3 config key is not a dictionary type, ignoring its value of: None
2019-01-25 14:08:51 Setting serverlessrepo timeout as (60, 60)
2019-01-25 14:08:51 Registering retry handlers for service: serverlessrepo
2019-01-25 14:08:51 No Parameters detected in the template
2019-01-25 14:08:51 2 resources found in the template
2019-01-25 14:08:51 Found '1' API Events in Serverless function with name 'HelloWorldFunction'
2019-01-25 14:08:51 Detected Inline Swagger definition
2019-01-25 14:08:51 Lambda function integration not found in Swagger document at path='/hello' method='get'
2019-01-25 14:08:51 Found '0' APIs in resource 'ServerlessRestApi'
2019-01-25 14:08:51 Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2019-01-25 14:08:51 1 APIs found in the template
2019-01-25 14:08:51 Event choose-service-name: calling handler
2019-01-25 14:08:51 Loading JSON file: C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\data\lambda\2015-03-31\service-2.json
2019-01-25 14:08:51 Event creating-client-class.lambda: calling handler
2019-01-25 14:08:51 The s3 config key is not a dictionary type, ignoring its value of: None
2019-01-25 14:08:51 Setting lambda timeout as (60, 60)
2019-01-25 14:08:51 Registering retry handlers for service: lambda
2019-01-25 14:08:51 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:08:51 No config file found
2019-01-25 14:08:51 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:08:51 No config file found
2019-01-25 14:08:51 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2019-01-25 14:08:51 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
2019-01-25 14:08:51 Localhost server is starting up. Multi-threading = True
2019-01-25 14:08:53 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2019-01-25 14:09:04 Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/hello", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/hello", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "prod", "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": "/hello"}, "queryStringParameters": null, "headers": {"Host": "localhost:3000", "Connection": "keep-alive", "Cache-Control": "max-age=0", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-IN,en;q=0.9,en-GB;q=0.8,en-US;q=0.7,hi;q=0.6", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "pathParameters": null, "stageVariables": null, "path": "/hello", "isBase64Encoded": false}
2019-01-25 14:09:04 Found one Lambda function with name 'HelloWorldFunction'
2019-01-25 14:09:04 Invoking app.lambdaHandler (nodejs8.10)
2019-01-25 14:09:04 Environment variables overrides data is standard format
2019-01-25 14:09:04 Loading AWS credentials from session with profile 'default'
2019-01-25 14:09:04 Resolving code path. Cwd=D:\sam-app.aws-sam\build, CodeUri=HelloWorldFunction
2019-01-25 14:09:04 Resolved absolute path to code is D:\sam-app.aws-sam\build\HelloWorldFunction
2019-01-25 14:09:04 Code D:\sam-app.aws-sam\build\HelloWorldFunction is not a zip/jar file
2019-01-25 14:09:04 Skipping building an image since no layers were defined
2019-01-25 14:09:04 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:09:04 No config file found
2019-01-25 14:09:04 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:09:04 No config file found
2019-01-25 14:09:04 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2019-01-25 14:09:04 Looking for auth config
2019-01-25 14:09:04 No auth config in memory - loading from filesystem
2019-01-25 14:09:04 Trying paths: ['C:\Users\nishant.ramesh\.docker\config.json', 'C:\Users\nishant.ramesh\.dockercfg']
2019-01-25 14:09:04 No config file found
2019-01-25 14:09:04 Looking for auth entry for 'docker.io'
2019-01-25 14:09:04 No entry found
2019-01-25 14:09:04 No auth config found
2019-01-25 14:09:09 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-01-25 14:09:09 Mounting D:\sam-app.aws-sam\build\HelloWorldFunction as /var/task:ro inside runtime container
2019-01-25 14:09:35 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 500 43
2019-01-25 14:09:35 Container was not created. Skipping deletion
2019-01-25 14:09:35 Exception on /hello [GET]
Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 246, in _raise_for_status
response.raise_for_status()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localnpipe/v1.35/containers/create

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask_compat.py", line 35, in reraise
raise value
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\apigw\local_apigw_service.py", line 153, in _request_handler
self.lambda_runner.invoke(route.function_name, event, stdout=stdout_stream_writer, stderr=self.stderr)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\lib\local_lambda.py", line 85, in invoke
self.local_runtime.invoke(config, event, debug_context=self.debug_context, stdout=stdout, stderr=stderr)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\lambdafn\runtime.py", line 86, in invoke
self._container_manager.run(container)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\manager.py", line 96, in run
container.create()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\container.py", line 130, in create
real_container = self.docker_client.containers.create(self._image, kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\models\containers.py", line 837, in create
resp = self.client.api.create_container(
create_kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\container.py", line 411, in create_container
return self.create_container_from_config(config, name)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\container.py", line 422, in create_container_from_config
return self._result(res, True)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 252, in _result
self._raise_for_status(response)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 248, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Drive sharing failed for an unknown reason'")
2019-01-25 14:09:36 127.0.0.1 - - [25/Jan/2019 14:09:36] "GET /hello HTTP/1.1" 502 -
2019-01-25 14:09:36 127.0.0.1 - - [25/Jan/2019 14:09:36] "GET /favicon.ico HTTP/1.1" 403 -

Expected result

Hello World should have executed successfully.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

OS: Windows 10 Enterprise

D:\sam-app>python --version
Python 3.7.0

D:\sam-app>sam --version
SAM CLI, version 0.10.0

D:\sam-app>aws --version
aws-cli/1.15.69 Python/3.7.0 Windows/10 botocore/1.10.68

D:\sam-app>node --version
v10.7.0

Most helpful comment

@jfuss is likely to be right, go in Docker settings and make sure the folder that contain your app is in a shared drive :
image

All 9 comments

@nishantrathee From the output: docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Drive sharing failed for an unknown reason'"). Looks like your drive is not shared with docker. Please make sure you are sharing the drive you are working on. If that is already set, I suggest toggling the shared settings for that drive and then restart your computer. We have seen docker not picking up the settings for whatever reason. We don't have any control over this sadly, as it is a docker issue.

@jfuss is likely to be right, go in Docker settings and make sure the folder that contain your app is in a shared drive :
image

Closing this issue, looks to be docker drive sharing.

Not sure of the proper etiquette here but I thought it would be useful to share that sorting the docker drive sharing fixed the problem for me too.

Adding the path to the sam application to the allowed list of drives to share worked for me.

Make sure to check for any Docker pop-ups that may be hidden behind your windows. Windows needed me to provide my windows credentials to actually allow the sharing of the drive.

The use of shared drives solved my problem. I switched from Windows Containers to Linux Containers and from this post the shared drive addition for the containers solved it.

image

Hi All,
I can not able to see "Shared Drives" option in setting menu.
image

Please help me with this issue.

Thanks,
Kinjal

In above window, click Resources -> File Sharing.

Please add the project location/path in Resources -> File Sharing
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GeoffreyBooth picture GeoffreyBooth  路  29Comments

enghwa picture enghwa  路  25Comments

matheusmaximo picture matheusmaximo  路  30Comments

kaukas picture kaukas  路  24Comments

terrywarwar picture terrywarwar  路  26Comments