On AWS I am creating a Lambda Function like this:
from __future__ import print_function
import time
import uuid
import sys
import socket
import elasticache_auto_discovery
from pymemcache.client.hash import HashClient
# ElastiCache settings
elasticache_config_endpoint = "my-endpoint"
nodes = elasticache_auto_discovery.discover(elasticache_config_endpoint)
nodes = map(lambda x: (x[1], int(x[2])), nodes)
memcache_client = HashClient(nodes)
######
# This function puts into memcache and get from it.
# Memcached is hosted using elasticache
######
def handler(event, context):
# Create a random UUID... this will be the sample element we add to the cache.
uuid_in = uuid.uuid4().hex
# Put the UUID to the cache.
memcache_client.set('uuid', uuid_in)
# Get the item (UUID) from the cache.
uuid_out = memcache_client.get('uuid')
# Print the results
if uuid_out == uuid_in:
# this print should see the CloudWatch Logs and Lambda console.
print "Success: Inserted: %s. Fetched %s from memcache." %(uuid_in, uuid_out)
else:
raise Exception("Bad value retrieved :(. Expected %s got %s." %(uuid_in, uuid_out))
return "Fetched value from Memcached"
I get this error, on the execution:
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
I have followed this tutorial: https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/Lambda.html
Any suggestion about the problem source?