sam build
たまたまコンパイルされたmysql2 gemを含めた場合を除いて、私にとってはうまく機能しています。この gem を含めると、ラムダは mysql2 が見つからないことを通知します。
私の中を見ると.aws-sam/build/MyLambdaFunctionName/vendor/bundle/ruby/2.5.0/gems
、mysql2-.0.5.2
ディレクトリがあります
私もbundle install --path vendor/bundle
ローカルでアップロードしようとしましたが、違いがありました
AWS Ruby Lambda 関数に mysql2 を含めるにはどうすればよいですか?
編集:に追加--use-container
するsam build
と、次の原因になります:
2019-01-15 09:58:39 Starting Build inside a container
2019-01-15 09:58:39 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-15 09:58:39 Building resource 'MyLambdaFunctionName'
Traceback (most recent call last):
File "/home/daver/venv/bin/sam", line 11, in <module>
sys.exit(cli())
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/samcli/commands/build/command.py", line 94, in cli
skip_pull_image, parameter_overrides) # pragma: no cover
File "/home/daver/venv/lib/python2.7/site-packages/samcli/commands/build/command.py", line 132, in do_cli
artifacts = builder.build()
File "/home/daver/venv/lib/python2.7/site-packages/samcli/lib/build/app_builder.py", line 129, in build
lambda_function.runtime)
File "/home/daver/venv/lib/python2.7/site-packages/samcli/lib/build/app_builder.py", line 201, in _build_function
runtime)
File "/home/daver/venv/lib/python2.7/site-packages/samcli/lib/build/app_builder.py", line 249, in _build_function_on_container
self._container_manager.run(container)
File "/home/daver/venv/lib/python2.7/site-packages/samcli/local/docker/manager.py", line 75, in run
is_image_local = self.has_image(image_name)
File "/home/daver/venv/lib/python2.7/site-packages/samcli/local/docker/manager.py", line 153, in has_image
self.docker_client.images.get(image_name)
File "/home/daver/venv/lib/python2.7/site-packages/docker/models/images.py", line 312, in get
return self.prepare_model(self.client.api.inspect_image(name))
File "/home/daver/venv/lib/python2.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/docker/api/image.py", line 245, in inspect_image
self._get(self._url("/images/{0}/json", image)), True
File "/home/daver/venv/lib/python2.7/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/docker/api/client.py", line 215, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/home/daver/venv/lib/python2.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/daver/venv/lib/python2.7/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))
Error: sam build failed
編集 2
同様の結果でpython 3.6を試しました:
2019-01-15 11:43:47 Starting Build inside a container
2019-01-15 11:43:47 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-15 11:43:47 Building resource 'MyLambdaFunctionName'
Traceback (most recent call last):
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 964, in send
self.connect()
File "/home/daver/venv/lib64/python3.6/site-packages/docker/transport/unixconn.py", line 42, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/daver/venv/lib64/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/daver/venv/lib64/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/http/client.py", line 964, in send
self.connect()
File "/home/daver/venv/lib64/python3.6/site-packages/docker/transport/unixconn.py", line 42, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/daver/venv/bin/sam", line 11, in <module>
sys.exit(cli())
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/commands/build/command.py", line 94, in cli
skip_pull_image, parameter_overrides) # pragma: no cover
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/commands/build/command.py", line 132, in do_cli
artifacts = builder.build()
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/lib/build/app_builder.py", line 129, in build
lambda_function.runtime)
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/lib/build/app_builder.py", line 201, in _build_function
runtime)
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/lib/build/app_builder.py", line 249, in _build_function_on_container
self._container_manager.run(container)
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/local/docker/manager.py", line 75, in run
is_image_local = self.has_image(image_name)
File "/home/daver/venv/lib64/python3.6/site-packages/samcli/local/docker/manager.py", line 153, in has_image
self.docker_client.images.get(image_name)
File "/home/daver/venv/lib64/python3.6/site-packages/docker/models/images.py", line 316, in get
return self.prepare_model(self.client.api.inspect_image(name))
File "/home/daver/venv/lib64/python3.6/site-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/docker/api/image.py", line 245, in inspect_image
self._get(self._url("/images/{0}/json", image)), True
File "/home/daver/venv/lib64/python3.6/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/docker/api/client.py", line 225, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/home/daver/venv/lib64/python3.6/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/daver/venv/lib64/python3.6/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Error: sam build failed
編集 3
もう少し。このエラーは、docker が実行されていないときに発生します。それが実行されているとき、私はまだエラーが発生します
2019-01-15 12:15:12 Starting Build inside a container
2019-01-15 12:15:12 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-15 12:15:12 Building resource 'MyLambdaFunctionName'
Fetching lambci/lambda:build-ruby2.5 Docker container image.......................................................................................................................................................................................
2019-01-15 12:15:32 Mounting /home/daver/code/project/project3/backend/code as /tmp/samcli/source:ro inside runtime container
Build Failed
'ruby' runtime has not been validated!
Running RubyBundlerBuilder:CopySource
Running RubyBundlerBuilder:RubyBundle
Error: RubyBundlerBuilder:RubyBundle - Bundler Failed:
編集 4
この失敗を aws-sam-cli の github ページにバグとして追加しました: https://github.com/awslabs/aws-sam-cli/issues/939