{"id":2311,"date":"2019-12-06T17:47:31","date_gmt":"2019-12-06T22:47:31","guid":{"rendered":"https:\/\/blogs.mathworks.com\/developer\/?p=2311"},"modified":"2019-12-06T17:48:05","modified_gmt":"2019-12-06T22:48:05","slug":"storing-parameters-in-aws-using-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/developer\/2019\/12\/06\/storing-parameters-in-aws-using-matlab\/","title":{"rendered":"Storing Parameters in AWS using MATLAB"},"content":{"rendered":"<p>In a previous blog post, <a href=\"https:\/\/blogs.mathworks.com\/developer\/2019\/10\/14\/notifications-from-matlab\/\" target=\"_blank\" rel=\"noopener noreferrer\">Notifications from MATLAB,<\/a> I showed how Amazon's Notification system (<a href=\"https:\/\/aws.amazon.com\/sns\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS SNS<\/a>) can be used from MATLAB service can be used to easily send information between endpoints in a distributed system, be they applications or people.<\/p>\r\n\r\n<p>In this short post I want to show how MathWorks tools can use another AWS service - the Simple Systems Manager (<a href=\"https:\/\/docs.aws.amazon.com\/systems-manager\/latest\/userguide\/what-is-systems-manager.html\" target=\"_blank\" rel=\"noopener noreferrer\">SSM<\/a>) 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. <a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-aws-dynamodb\" target=\"_blank\" rel=\"noopener noreferrer\">AWS DynamoDB<\/a>), however for a simple flag or individual variable this can be overkill.\u00a0 This use case is a common one and even XKCD has this <a href=\"https:\/\/xkcd.com\/974\/\" target=\"_blank\" rel=\"noopener noreferrer\">covered<\/a>.<\/p>\r\n\r\n<p>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 <a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-aws-ssm\" target=\"_blank\" rel=\"noopener noreferrer\">MATLAB interface for AWS SSM<\/a> from GitHub.<\/p>\r\n\r\n<p>Change to the <em>Software\/MATLAB<\/em> directory in the package and run the <em>startup.m<\/em>\u00a0script. Then create an SSM client:<\/p>\r\n\r\n<pre>ssm = aws.simplesystemsmanagement.AWSSimpleSystemsManagementClient();\r\nssm.initialize();\r\n<\/pre>\r\n\r\n<p>Create a request and set the name, value and type of our variable:<\/p>\r\n\r\n<pre>\r\n% Create a request to put a parameter into SSM\r\nputParameterRequest = aws.simplesystemsmanagement.model.PutParameterRequest();\r\nputParameterRequest.setName('myParameterName');    % Name\r\nputParameterRequest.setValue('myParameterValue');  % Value\r\nputParameterRequest.setType('String');             % Datatype\r\n<\/pre>\r\n\r\n<em>Put<\/em> the value to the service:\r\n\r\n<pre>\r\n% Store the parameter \r\nputParameterResult = ssm.putParameter(putParameterRequest);\r\n<\/pre>\r\n\r\n<p>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 <em>export<\/em> like function if you wished.<\/p>\r\n\r\n<p>Here we see the value reflected in the SSM web portal:<\/p>\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/developer\/files\/ssm1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"593\" src=\"https:\/\/blogs.mathworks.com\/developer\/files\/ssm1-1024x593.png\" alt=\"\" class=\"alignleft size-large wp-image-2319\" \/><\/a>\r\n<br\/>\r\n<p>We can also read the value back, delete it etc.:<\/p>\r\n\r\n<pre>\r\n% Create a request to fetch a parameter from SSM\r\ngetParameterRequest = aws.simplesystemsmanagement.model.GetParameterRequest();\r\ngetParameterRequest.setName('myParameterName');\r\n\r\n% Fetch the result\r\ngetParameterResult = ssm.getParameter(getParameterRequest);\r\nparameter = getParameterResult.getParameter();\r\nresultValue = parameter.getValue();\r\n<\/pre>\r\n\r\n<p>Please go to the <a href=\"https:\/\/github.com\/mathworks-ref-arch\/matlab-aws-ssm\" rel=\"noopener noreferrer\" target=\"_blank\">GitHub page<\/a> for the interface for more details.<\/p>\r\n\r\n<p>\r\nIn 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.<\/p> \r\n\r\n<p>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! \r\n<\/p>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/developer\/files\/ssm1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>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... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/developer\/2019\/12\/06\/storing-parameters-in-aws-using-matlab\/\">read more >><\/a><\/p>","protected":false},"author":135,"featured_media":2319,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,30,21,8,10],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/2311"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/users\/135"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/comments?post=2311"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/2311\/revisions"}],"predecessor-version":[{"id":2329,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/posts\/2311\/revisions\/2329"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/media\/2319"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/media?parent=2311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/categories?post=2311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/developer\/wp-json\/wp\/v2\/tags?post=2311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}