Test the deployed endpoint with a GET request.
(self, endpoint_url)
| 3528 | sys.stderr = open(os.devnull, "w") |
| 3529 | |
| 3530 | def touch_endpoint(self, endpoint_url): |
| 3531 | """ |
| 3532 | Test the deployed endpoint with a GET request. |
| 3533 | """ |
| 3534 | |
| 3535 | # Private APIGW endpoints most likely can't be reached by a deployer |
| 3536 | # unless they're connected to the VPC by VPN. Instead of trying |
| 3537 | # connect to the service, print a warning and let the user know |
| 3538 | # to check it manually. |
| 3539 | # See: https://github.com/Miserlou/Zappa/pull/1719#issuecomment-471341565 |
| 3540 | if "PRIVATE" in self.stage_config.get("endpoint_configuration", []): |
| 3541 | print( |
| 3542 | click.style("Warning!", fg="yellow", bold=True) + " Since you're deploying a private API Gateway endpoint," |
| 3543 | " Zappa cannot determine if your function is returning " |
| 3544 | " a correct status code. You should check your API's response" |
| 3545 | " manually before considering this deployment complete." |
| 3546 | ) |
| 3547 | return |
| 3548 | |
| 3549 | touch_path = self.stage_config.get("touch_path", "/") |
| 3550 | req = requests.get(endpoint_url + touch_path) |
| 3551 | |
| 3552 | # Sometimes on really large packages, it can take 60-90 secs to be |
| 3553 | # ready and requests will return 504 status_code until ready. |
| 3554 | # So, if we get a 504 status code, rerun the request up to 4 times or |
| 3555 | # until we don't get a 504 error |
| 3556 | if req.status_code == 504: |
| 3557 | i = 0 |
| 3558 | status_code = 504 |
| 3559 | while status_code == 504 and i <= 4: |
| 3560 | req = requests.get(endpoint_url + touch_path) |
| 3561 | status_code = req.status_code |
| 3562 | i += 1 |
| 3563 | |
| 3564 | if req.status_code >= 500: |
| 3565 | raise ClickException( |
| 3566 | click.style("Warning!", fg="red", bold=True) |
| 3567 | + " Status check on the deployed lambda failed." |
| 3568 | + " A GET request to '" |
| 3569 | + touch_path |
| 3570 | + "' yielded a " |
| 3571 | + click.style(str(req.status_code), fg="red", bold=True) |
| 3572 | + " response code." |
| 3573 | ) |
| 3574 | |
| 3575 | |
| 3576 | #################################################################### |
no outgoing calls