AWS Lambda to start and stop ec2, endpoint connectionerror

0

I have followed the article in setting up AWS Lambda to stop and start my ec2 instance but I get following error while doing test run

Test Event Name stop

Response { "errorMessage": "Could not connect to the endpoint URL: "https://ec2.ap-northeast-2a.amazonaws.com/"", "errorType": "EndpointConnectionError", "stackTrace": [ " File "/var/task/lambda_function.py", line 7, in lambda_handler\n ec2.stop_instances(InstanceIds=instances)\n", " File "/var/runtime/botocore/client.py", line 530, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File "/var/runtime/botocore/client.py", line 944, in _make_api_call\n operation_model, request_dict, request_context\n", " File "/var/runtime/botocore/client.py", line 966, in _make_request\n return self._endpoint.make_request(operation_model, request_dict)\n", " File "/var/runtime/botocore/endpoint.py", line 119, in make_request\n return self._send_request(request_dict, operation_model)\n", " File "/var/runtime/botocore/endpoint.py", line 207, in _send_request\n exception,\n", " File "/var/runtime/botocore/endpoint.py", line 361, in _needs_retry\n request_dict=request_dict,\n", " File "/var/runtime/botocore/hooks.py", line 412, in emit\n return self._emitter.emit(aliased_event_name, **kwargs)\n", " File "/var/runtime/botocore/hooks.py", line 256, in emit\n return self._emit(event_name, kwargs)\n", " File "/var/runtime/botocore/hooks.py", line 239, in _emit\n response = handler(**kwargs)\n",

zab
質問済み 10ヶ月前473ビュー
1回答
0

It looks like your Lambda function is configured to run in a VPC and within that VPC it is unable to reach the EC2 API endpoint. Possible solutions are:

  1. Don't assign the Lambda function to a VPC.
  2. Use a NAT Gateway and internet gateway to provide your Lambda function access to public IP address so it can reach the EC2 API endpoint.
  3. Create a VPC private endpoint for the EC2 service.

Note that options (2) and (3) incur extra costs.

profile pictureAWS
エキスパート
回答済み 10ヶ月前
profile pictureAWS
エキスパート
Uri
レビュー済み 10ヶ月前
profile pictureAWS
エキスパート
レビュー済み 10ヶ月前
profile picture
エキスパート
レビュー済み 10ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ