Question

How to create droplet in aws lambda

I am trying to implement a lambda function that creates a droplet. However, after the creation line of code, lambda stucks, and timeouts. In addition, in most of cases, it cannot create a droplet. The result is the same even I have extended the timeout range. Also, it means lots of billing from aws. I am running the same code in local python (in my laptop), there is no problem. What can I do? here is the code:

import digitalocean
manager = digitalocean.Manager(token="token")

my_droplets = manager.get_all_droplets()
for droplet in my_droplets:
    d = droplet.load()
    if d.name == 'mefJitsi3':
        print('found')
        print(d.ip_address)
        exit()

#print(my_droplets)
print('not found')

keys = manager.get_all_sshkeys()
droplet = digitalocean.Droplet(token="token",
                               name='mefJitsi3',
                               region='fra1', # Amster
                               image='58038226', # Ubuntu 14.04 x64
                               size_slug='s-1vcpu-1gb',  # 512MB
                               ssh_keys=keys, #Automatic conversion
                               backups=False)
droplet.create() # code stucks here

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Looks like the issue could be in the Lambda execution environment or some limitations around running asynchronous calls. Might be worth checking out the local python debugging tools for Lambda: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-python.html