I'm new to microservices, so trying to do a little app.
This is my current design:
Create two LambdaServices:
1) GetSomeData (string domainName, string nextSNS, ILambdaContext context)
2) StoreSomeData (string jsonData)
Part 1:
My understanding of microservice is that each function should do only one thing. So "GetSomeData" takes a domain name, does a web call, parses the results into JSON. Then I need to store it in an RDS database in StoreSomeData. But in the future, I might want to just get the data, or do something else with it.
The function I need 99% of the time now, is really GetAndStoreSomeData. But if I do that, I'm not a microservice, right?
So I'm thinking if a program just wants the JSON back from "GetSomeData", it will just pass null in the nextSNS. But if it wants to store the data, it will pass an SNSTopicName or arn in nextSNS, then "GetSomeData" will publish a message to that SNS with the JSON response.
The process will be kicked off by some other process that I haven't totally figured out yet, that will pick some domains from the RDS database, and probably call API-Gateway to launch "GetSomeData". I'll probably have to run it from some type of scheduler.
I'd like to know if this is a good design. I just got "GetSomeData" published and tested without the "nextSNS" parm.
Part 2:
If "GetSomeData" needs to publish to SNS, how can I do that without storing the IAM credentials. Can I use a role? Or I have to use the secret access key, which maybe I could put in an environment variable to at least keep it out of the code.
I was thinking of cloning this method: https://gist.github.com/bkizzy/2705156 to publish the SNS message. But then I found a Java sample that is only about 6 lines of code for the call here: Lambda does not trigger SNS event. Chaining AWS lambdas with SNS. Is there similar short way to do the same from C#? I couldn't find much on the Amazon site on how to publish SNS other than the raw request/response. (https://docs.aws.amazon.com/sns/latest/api/API_Publish.html)