python - Obtain EC2 instance IP from AWS lambda function and use requests library -




writing lambda function on amazon aws lambda. accesses url of ec2 instance, on running web rest api. lambda function triggered alexa , coded in python language (python3.x).

currently, have hard coded url of ec2 instance in lambda function , ran alexa skill.

want lambda function automatically obtain ip ec2 instance, keeps changing whenever start instance. ensure don't have go code , hard code url each time start ec2 instance.

stumbled upon similar question on so, unanswered. however, there reply indicated updating iam roles. have created iam roles other purposes before, still not used it. possible? require managing of security groups of ec2 instance? need set permissions/configurations/settings? how can lambda code achieve this?

additionally, pip installed requests library on system, , tried uploading '.zip' file structure :

  • rest.zip/
    • requests library folder
    • index.py

using urllib library

when use zip files code upload (i edit code inline), can't accesse index.py file run code

you could using boto3, advise against architecture. better approach use load balancer (even if have 1 instance), , use cname record of load balancer in application (this not change long lb exists).

an better way, if have access own domain name, create cname record , point address of load balancer. can happily use dns name in lambda function without fear ever change.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -