Nisman
Nisman

Reputation: 1309

What is the best way to share some data (like fileds name for a dynamodb table ) among multiple lambda functions in serverless framework?

I want a single place for all the data that multiple lambda functions need them. So that I can modify/change/add the data freely without any side effect. How can I achieve this requirement when building a serverless application using serverless framework?

Upvotes: 0

Views: 25

Answers (1)

stdunbar
stdunbar

Reputation: 17455

"Best" is a relative term but one way is with the systems manager parameter store. You don't specify your programming language but some code I have in Java looks something like:

AWSSimpleSystemsManagement ssmClient = AWSSimpleSystemsManagementClientBuilder.standard().build();

GetParameterRequest getParameterRequest = new GetParameterRequest()
                .withName("/path/to/creds/cred1")
                .withWithDecryption(Boolean.TRUE);

String parameterValue = getParameterRequest.getParameter().getValue();

with things like null checks left out.

This does two things. First, it creates a single place to store common for things like credentials (or table names) so that you don't need to store them elsewhere. Secondly, is that it allows you to create a hierarchy of parameters so that, for example, you could have parameters for your development, staging, and production environments in one place. Plus you can permission the parameters per environment so that, for example, the development IAM role can't see the production parameters.

I'm showing it with encrypted strings - that isn't needed if you don't want.

Other ways could be a DynamoDB or other persistent store like a RDS.

Upvotes: 1

Related Questions