반응형
API 로컬 테스트를 할 수 있게
로컬에서 구동시켜봤다.
>sam local start-api
설치 후 오랜만에 구동해보는 건지 구동이 안됐다.
Traceback (most recent call last):
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py",
line 193, in _run_module_as_main
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\runpy.py",
line 85, in _run_code
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\__main__.py", line 12, in <module>
cli(prog_name="sam")
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 96, in wrapped
raise exception # pylint: disable=raising-bad-type
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\telemetry\metrics.py", line 62, in wrapped
return_value = func(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\start_api\cli.py", line 86, in cli
parameter_overrides,
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\start_api\cli.py", line 142, in do_cli
aws_profile=ctx.profile,
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\commands\local\cli_common\invoke_context.py", line 136, in __enter__
if not self._container_manager.is_docker_reachable:
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\manager.py", line 47, in is_docker_reachable
self.docker_client.ping()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\client.py", line 187, in ping
return self.api.ping(*args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\daemon.py", line 166, in ping
return self._result(self._get(self._url('/_ping'))) == 'OK'
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 230, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 543, in get
return self.request('GET', url, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
chunked=chunked,
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\urllib3\connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\client.py", line 1252, in request
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\client.py", line 1298, in _send_request
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\client.py", line 1247, in endheaders
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\client.py", line 1026, in _send_output
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\client.py", line 966, in send
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipeconn.py", line 32, in connect
sock.connect(self.npipe_path)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 23, in wrapped
return f(self, *args, **kwargs)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 72, in connect
raise e
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 59, in connect
0
pywintypes.error: (2, 'CreateFile', '지정된 파일을 찾을 수 없습니다.')
위와 같이 에러가 표시되며 실행이 안됐다.
왜 실행이 안되지 하며
다시 설치 과정을 다시 짚어보다가 도커 실치 과정을 봤다.
도커를 실행하고 나니 제대로
서비스가 올라갔다.
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
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
2020-09-09 23:25:23 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
도커가 실행되지 않고 있어서 로컬 실행이 안되었던 것이다.
서비스가 올라간 후 해당 서비스로 브라우저로 접속해보면
http://127.0.0.1:3000/hello
아래와 같이 도커 이미지를 마운트 하는 작업을 그때서야 시작하고
도커에서 공유 폴더 수락하겠냐고 경고가 나오면 수락해줬다.
2020-09-09 23:30:52 127.0.0.1 - - [09/Sep/2020 23:30:52] "GET / HTTP/1
.1" 403 -
2020-09-09 23:30:52 127.0.0.1 - - [09/Sep/2020 23:30:52] "GET /favicon
.ico HTTP/1.1" 403 -
Invoking app.lambdaHandler (nodejs12.x)
Fetching lambci/lambda:nodejs12.x Docker container image.....................................................................................................................................................................................................................................................................................
Mounting C:\Users\ej\daonstar\nuxt\sam-app\.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 01f99077-c224-1bdf-84fa-21ea94f2387b Version: $LATEST
END RequestId: 01f99077-c224-1bdf-84fa-21ea94f2387b
REPORT RequestId: 01f99077-c224-1bdf-84fa-21ea94f2387b Init Duration:
1312.10 ms Duration: 6.05 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 40 MB
No Content-Type given. Defaulting to 'application/json'.
2020-09-09 23:31:36 127.0.0.1 - - [09/Sep/2020 23:31:36] "GET /hello HTTP/
1.1" 200 -
2020-09-09 23:31:36 127.0.0.1 - - [09/Sep/2020 23:31:36] "GET /favicon
.ico HTTP/1.1" 403 -
로컬에 도커 대시보드의 화면이다.
관련 도커 이미지가 올라와 있다.
기본 예제를 시행해서인지 생각보단 쉽다.
결과는 브라우저에 아래와 같이 잘 나왔다.
{"message":"hello world"}
반응형