{"id":10281,"date":"2017-02-08T11:46:53","date_gmt":"2017-02-08T02:46:53","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=10281"},"modified":"2017-02-08T14:23:57","modified_gmt":"2017-02-08T05:23:57","slug":"aws-datapipeline-passing-parameters-to-ec2-resource-using-user-data-file","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/en\/aws-datapipeline-passing-parameters-to-ec2-resource-using-user-data-file\/","title":{"rendered":"AWS DataPipeline: Passing parameters to EC2 resource using user-data file"},"content":{"rendered":"<p>Recently I had the privilege to work on a project where I had to implement\u00a0<a href=\"https:\/\/aws.amazon.com\/datapipeline\/\">AWS Datapipeline<\/a>. Reading through the documentation, it was not that difficult to understand the basic concepts. As stated in the AWS Datapipeline homepage:<\/p>\n<blockquote><p>AWS Data Pipeline is a web service that helps you reliably process and move data between different AWS compute and storage services, as well as on-premise data sources, at specified intervals.<\/p><\/blockquote>\n<p>Basically, a <em>datapipeline<\/em> will allow you to run an EC2 instance using scheduled intervals or on-demand activation so as to manipulate data and be able to transfer the output to other AWS services. For the project that I worked on, I simply had to run a datapipeline so that it will run a shell script to get data from AWS S3, process those data, then upload the processed data back to AWS S3. Going through the documentation, you will see two ways on how you can pass user-data to the generated instance when the pipeline is activated. First is via the <strong>command<\/strong> field and the second is the S<strong>cript Uri.\u00a0<\/strong>Though both can not exist at the same time in your configuration, you have to choose only one.<\/p>\n<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-10285\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001.png\" alt=\"\" width=\"675\" height=\"259\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001.png 1278w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001-300x115.png 300w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001-768x294.png 768w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001-1024x393.png 1024w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_001-728x279.png 728w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/a>\n<h2>Passing parameters<\/h2>\n<p>Based on the <a href=\"http:\/\/docs.aws.amazon.com\/datapipeline\/latest\/DeveloperGuide\/dp-object-shellcommandactivity.html#d0e19539\">documentation<\/a>, you will learn that it is not possible to pass parameters to a shell script provided in the <strong>Script Uri <\/strong>field and that you should use <strong>Command <\/strong>field instead. I was disappointed in this because my shell script needs to take in two arguments in order for it to execute completely. Luckily, there <strong>IS\u00a0<\/strong>a way to pass parameters to the script file and it is very easy.<a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_002.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10286\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_002.png\" alt=\"\" width=\"465\" height=\"285\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_002.png 465w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2017\/02\/Selection_002-300x184.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/a><\/p>\n<p>Just add another optional field, <strong>Script Argument<\/strong>. Via the documentation, this is only used for <strong>Command\u00a0<\/strong>field; but I have learned that we can also use this for the <strong>Script Uri. <\/strong>And in your shell script file, you can access the values using <strong>$n<\/strong> where <strong>n<\/strong> is equal to number of the script argument in the order. In case of the example above, <strong>$1<\/strong> will have a value of \"<strong>Hello World<\/strong>\" while <strong>$2<\/strong> will have a value of <strong>300<\/strong>.<\/p>\n<p>That's it! Hopefully this will help someone in there quest to master the <em><strong>Datapipeline.\u00a0<\/strong><\/em>And that AWS should update there documentation so as not to give it's users a hard time with such cases.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I had the privilege to work on a project where I had to implement\u00a0AWS Datapipeline. Reading through t&#8230;<\/p>\n","protected":false},"author":1,"featured_media":10288,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"10281","footnotes":""},"categories":[20,83],"tags":[],"class_list":{"0":"post-10281","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-aws","8":"category-devops","9":"en-US"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/10281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=10281"}],"version-history":[{"count":2,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/10281\/revisions"}],"predecessor-version":[{"id":10294,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/10281\/revisions\/10294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/10288"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=10281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=10281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=10281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}