Storing Parameters in AWS using MATLAB
In a previous blog post, Notifications from MATLAB, I showed how Amazon's Notification system (AWS SNS) can be used from MATLAB service can be used to easily send information between endpoints in a distributed system, be they applications or people.
In this short post I want to show how MathWorks tools can use another AWS service - the Simple Systems Manager (SSM) to exchange information between parts of a distributed system. When running locally we frequently use environment variables as an easy way to pass simple values or state between processes. However when moving to a distributed system that isn't an option. We could use a database as a shared information store (e.g. AWS DynamoDB), however for a simple flag or individual variable this can be overkill. This use case is a common one and even XKCD has this covered.
What if we could set an environment variable like value that would be persistent and accessible across a cloud based deployment? Start by downloading the MATLAB interface for AWS SSM from GitHub.
Change to the Software/MATLAB directory in the package and run the startup.m script. Then create an SSM client:
ssm = aws.simplesystemsmanagement.AWSSimpleSystemsManagementClient(); ssm.initialize();
Create a request and set the name, value and type of our variable:
% Create a request to put a parameter into SSM putParameterRequest = aws.simplesystemsmanagement.model.PutParameterRequest(); putParameterRequest.setName('myParameterName'); % Name putParameterRequest.setValue('myParameterValue'); % Value putParameterRequest.setType('String'); % DatatypePut the value to the service:
% Store the parameter putParameterResult = ssm.putParameter(putParameterRequest);
This value is now accessible using a number of language APIs using AWS permission controls, making it easy to securely tie loosely coupled parts of a system together. You could wrap this in your own one-liner export like function if you wished.
Here we see the value reflected in the SSM web portal:
We can also read the value back, delete it etc.:
% Create a request to fetch a parameter from SSM getParameterRequest = aws.simplesystemsmanagement.model.GetParameterRequest(); getParameterRequest.setName('myParameterName'); % Fetch the result getParameterResult = ssm.getParameter(getParameterRequest); parameter = getParameterResult.getParameter(); resultValue = parameter.getValue();
Please go to the GitHub page for the interface for more details.
In conclusion, whether you just want to use AWS's Parameter Store to hold a one-off persistent counter or an S3 URL or you want to integrate MATLAB based compute into a complex, multi-service, global workflow then this package can be used to enable it.
System Manager has many features, of which Parameter Store is just one, if you have ideas on how MATLAB could work with other Systems Manager features please let us know!
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.