noviksv / tg-bot-aws

0 stars 0 forks source link

Investigation: how to run code locally? #6

Closed noviksv closed 2 months ago

noviksv commented 2 months ago

Need to add ability to run code locally Also split code for infra and application by directories

noviksv commented 2 months ago

requests.exceptions.SSLError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /*******bottoken******/sendMessage?chat_id=790022784&parse_mode=HTML&text=Current%20weather%20is%20%60%60%60%7B'temp':%2023.17,%20'feels_like':%2022.53,%20'temp_min':%2021.43,%20'temp_max':%2024.51,%20'pressure':%201011,%20'humidity':%2038%7D%60%60%60 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')))

noviksv commented 2 months ago

Issue was about corparate firewall (Zscaler) "changed" root cert. Need to copy cert to WSL https://stackoverflow.com/questions/72167566/wsl-docker-curl-60-ssl-certificate-problem-unable-to-get-local-issuer-certi

and add to.bashrc export REQUESTS_CA_BUNDLE=/usr/local/share/ca-certificates/Zscaler.crt \n\n export AWS_CA_BUNDLE=/etc/ssl/certs/Amazon_Root_CA_1.pem

noviksv commented 2 months ago

options how to run locally: Sam + Terraform

sam local start-lambda --hook-name terraform -var-file=terraform.tfvars 
aws lambda invoke --function-name weather_bot --endpoint-url http://localhost:3001 --no-verify-ssl --cli-binary-format raw-in-base64-out --payload '{"key": "value"}' response.json

Still issue with Zscaller certificate

Local python add fix to code

 #fix for local testing
if __name__ == "__main__":
    event = {}
    context = {}
    lambda_handler(event, context)
noviksv commented 2 months ago

Looks like for the part of connetctions we can't use this fix

Issue was about corparate firewall (Zscaler) "changed" root cert. Need to copy cert to WSL https://stackoverflow.com/questions/72167566/wsl-docker-curl-60-ssl-certificate-problem-unable-to-get-local-issuer-certi

and add to.bashrc export REQUESTS_CA_BUNDLE=/usr/local/share/ca-certificates/Zscaler.crt

additionnaly add export AWS_CA_BUNDLE=/etc/ssl/certs/Amazon_Root_CA_1.pem