Race condition with AWS Lambda
Instead of deleting the hostname from DynamoDB, why not lock the hostname in DynamoDB?. If each item in DynamoDB corresponds to a unique hostname, then you can use a conditional write like the following and only try to acquire a hostname if it is not already acquired. You condition on the instanceid attribute

Unused hostname: {hostname: 'tom-sawyer'}
UpdateItem to do a conditional write on {hostname: 'tom-sawyer'} where the condition is attribute_not_exists(instanceid) and the update expression is SET instanceid = :instanceid and the ExpressionAttributeValues map is {:instanceid: 'deadbeef'}. Basically, you only allow DynamoDB to assign an instance to a hostname when it does not have an instanceid set.
Used hostname: {hostname: 'tom-sawyer', 'instanceid'='deadbeef'}
UpdateItem to do a conditional write on {hostname: 'tom-sawyer'} where the condition is attribute_exists(instanceid) AND instanceid = :instanceid and the update expression is REMOVE instanceid. Basically, you only allow DynamoDB to un-assign a specific instance when the instance id being removed is set and matches the record for that hostname.
Workflow : I have a python AWS lambda function that basically looks up a pool of hostnames in dynamo DB (json) and attaches one of them to an instance(that spins up) and then deletes that hostname from dynamo db so as not be used again for another instance.
Problem : As soon as instance spins up it sends a notification to SNS service that triggers lambda to assign it a hostname from available hostnames. There are times when multiple instances come up together and they both trigger the same lambda function simultaneously (2 threads). Their could be a race condition where both functions are looking at the dynamo db for available hostnames and sign the same one. How do I resolve this problem ?
Any ideas ?