Report this

What is the reason for this report?

How to create droplet in aws lambda

Posted on February 3, 2020

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


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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.