0

My requirement is that I need to write a AWS Lambda function that needs to do some processing and then invoke a URL. These URLs would very from stack to stack.

So in stack 1 Lambda the URL can be http://do-something.com and in stack 2 the URL can be http://do-nothing.com

I would have my Lambda jar built out of Jenkins, so I cannot put those details within the Lambda Jar as well

My question is what are the ways of configuring such things in Lambda. One approach that I could think of is that put that URL in a file in a standard bucket and Lambda would read that everytime it is invoked. Seems to be non-efficient because it has to read that everytime.

Any other suggestions or recommended good practices.

2
  • How would you approach this without a lambda? Commented Feb 3, 2016 at 15:43
  • Without Lambda I would done this then there would be a config file that would have told my app about the URL to use Commented Feb 3, 2016 at 15:48

2 Answers 2

1

With the advent of 'Environment variables' for AWS Lambda, this can be easily achieved using the same.

So using 'Environment variables' is the way to go for such scenarios

Sign up to request clarification or add additional context in comments.

Comments

0

The way I've solved this is by using the name of the lambda function as a key into a DynamoDB table. Deployment information is encoded into the lambda function name when you deploy it to AWS.

For example, first the lambda would be deployed with a DEV tag attached to the name:

$ aws lambda update-function-code --function-name myLambda_DEV 
    --s3-bucket lambda_s3_release_bucket --s3-key myLambda-1.0.0.jar --publish

Then in the lambda, the function name is read from the context and used to read from the config table:

public Response handleRequest(Request request, Context context) {
    String functionName = context.getFunctionName();
    AmazonDynamoDBClient dbclient = new AmazonDynamoDBClient();
    DynamoDB configdb = new DynamoDB(dbclient);
    Table config = dynamoDB.getTable("config_" + functionName);
    String url = config.getItem("url");
    ...
}

And the DynamoDB has a table called config_myLambda_DEV that looks like this:

 name   | value
 -------+-------------------------
 url    |  http://do-something.com
 ...    |

While the call to DynamoDB (or S3, etc.) may be relatively slow compared to the rest of your lambda, in practice lambda functions get reused. You can load and cache the information on the first invocation, and use the values from memory on subsequent calls.

1 Comment

Thanks ataylor, this is pretty much on similar lines that I was thinking, except that instead of DynamoDB I was planning in using S3. Can you please elaborate more on cache part. I am not sure if we can cache anything in Lambda, coz they are all stateless

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.