<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: guutong</title>
    <description>The latest articles on DEV Community by guutong (@guutong).</description>
    <link>https://dev.to/guutong</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F111428%2F4f9b90d9-4498-40a0-902f-971ae214f4ff.jpeg</url>
      <title>DEV Community: guutong</title>
      <link>https://dev.to/guutong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/guutong"/>
    <language>en</language>
    <item>
      <title>AWS Lambda - Getting Started with Dollar Cost Averaging</title>
      <dc:creator>guutong</dc:creator>
      <pubDate>Thu, 04 May 2023 03:04:22 +0000</pubDate>
      <link>https://dev.to/guutong/aws-lambda-getting-started-with-dollar-cost-averaging-2869</link>
      <guid>https://dev.to/guutong/aws-lambda-getting-started-with-dollar-cost-averaging-2869</guid>
      <description>&lt;h2&gt;
  
  
  AWS Lambda - Getting Started with Dollar Cost Averaging
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Investing carries risks. Investors should study the information before making an investment decision.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The inspiration for this study came from seeing someone in a group trying to post about their investment journey every day. I wanted to try being diligent like them, as shown in the picture below 👇👇👇👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--va3qMO85--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ius3u29f8xkaoqw0c2b4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--va3qMO85--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ius3u29f8xkaoqw0c2b4.png" alt="Inspiration" width="800" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, I'm too lazy to open the app and make a purchase every day like they do😵 So, I decided to automate🤖 the process using AWS Lambda Function, which allows us to run code serverlessly🚀 and pay only for what we use. I think it's perfect for testing out dollar cost averaging as a beginner investor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xHV47gTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z70jf2nif6klognyf7e1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xHV47gTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z70jf2nif6klognyf7e1.png" alt="AWS Lambda Function Price" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  First, let's create an AWS Lambda Function
&lt;/h3&gt;

&lt;p&gt;Log in to the AWS Management Console and search for Lambda:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--92EBo4A7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31hlyd3fouoyx68e837t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--92EBo4A7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31hlyd3fouoyx68e837t.png" alt="Create function" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click "Create function" and select "Author from scratch"&lt;/li&gt;
&lt;li&gt;Enter a function name, such as "MyDollarCostAveragingFunction"&lt;/li&gt;
&lt;li&gt;Choose a runtime for the function, such as Python or Node.js, Java, etc. (Python is used in this example)&lt;/li&gt;
&lt;li&gt;Create or select a new IAM Role for the Lambda Function&lt;/li&gt;
&lt;li&gt;Click "Create function" and wait for AWS to create the function...&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Next, we will write or upload code for the Lambda Function
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n-fvacf6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekcumdy1c5lhdtipl45g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n-fvacf6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekcumdy1c5lhdtipl45g.png" alt="Lambda Function" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1.Write code for the function using the initial language you chose. The lambda handler will be provided, and you can add the remaining code.&lt;br&gt;
(Note: You can write the code on your machine and then .zip it to "Upload")&lt;br&gt;
2.Once the code is complete, you can test it by clicking "Test". A dialog will pop up, allowing you to create a simulated event to call your Lambda function (in this case, we don't need to send any parameters).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VkOQ_MZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjcq36wv43a9zs5o055d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VkOQ_MZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjcq36wv43a9zs5o055d.png" alt="Create event" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Test the Lambda Function with the event you created, and if everything works correctly, you can deploy it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K8rJ3F3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n3tc6uwze14hr2eeb2j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K8rJ3F3F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n3tc6uwze14hr2eeb2j.png" alt="Test event result" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.In this example, the Lambda Function will call an API to create a market price order at the current time, as the goal is to invest regularly with the same amount of money.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In dollar cost averaging, the investor decides only two parameters: the fixed amount of money to invest each time period (i.e. the amount that is available to invest) and how often the funds are invested. &lt;a href="https://en.wikipedia.org/wiki/Dollar_cost_averaging"&gt;https://en.wikipedia.org/wiki/Dollar_cost_averaging&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Ai35UC3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1h1xoqzsnjf1gnl03a7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Ai35UC3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1h1xoqzsnjf1gnl03a7.png" alt="Completed code" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Additional Information
&lt;/h4&gt;

&lt;p&gt;For Python, if you want to add other libraries not provided by Lambda Function, you can do so on your machine as follows:&lt;br&gt;
Open a terminal, create a folder called 'python', and install the requests library for API calls (make sure Python is installed on your machine first)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir python
$ cd python
$ pip3 install requests -t .
$ zip -r python.zip .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BQefif9z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uidaeth80a6u0kv7i4j0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BQefif9z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uidaeth80a6u0kv7i4j0.png" alt="Create Layer" width="800" height="785"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Upload the created .zip file, then "Create" a new Layer. Copy the ARN of the created Layer and add it to your Lambda Function by clicking "Add a layer" and selecting "Specify an ARN". Paste the copied Layer ARN and click "Verify".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xzts0Yd---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8e145nj8qk83xup4il4l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xzts0Yd---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8e145nj8qk83xup4il4l.png" alt="Add Layer to Function" width="800" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BGQcDs49--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mykxsx3pn85vavxtfv08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BGQcDs49--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mykxsx3pn85vavxtfv08.png" alt="Result of layer added" width="800" height="85"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can use the requests library in your Lambda Function.&lt;/p&gt;




&lt;h3&gt;
  
  
  Lastly, we will set up an Event Trigger to call the function daily
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7KugQ7-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/el1glepanzmj6rbrt47v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7KugQ7-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/el1glepanzmj6rbrt47v.png" alt="Lambda function diagram&amp;lt;br&amp;gt;
" width="800" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--emoEUJdp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xoiuxd0ep1sddtcnlj8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--emoEUJdp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xoiuxd0ep1sddtcnlj8j.png" alt="Add event" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the Lambda Function page, click "Add trigger"&lt;/li&gt;
&lt;li&gt;Select "EventBridge (CloudWatch Events)" from the list&lt;/li&gt;
&lt;li&gt;Create a new Event Rule by clicking "Create a new rule"&lt;/li&gt;
&lt;li&gt;Enter a name for the Rule, such as "DailyTrigger"&lt;/li&gt;
&lt;li&gt;Set the Schedule expression to call the function daily by entering &lt;code&gt;cron(0 12 * * ? *)&lt;/code&gt;, which means every day at 12:00 (UTC time)&lt;/li&gt;
&lt;li&gt;Click "Add" to add the Trigger to your Lambda function&lt;/li&gt;
&lt;li&gt;Click "Save" to save the new Trigger settings&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZtRrYVCC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkyksna9aqmkg786gz8j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZtRrYVCC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkyksna9aqmkg786gz8j.png" alt="Lambda function result" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've followed the steps above, your Lambda function will be called daily as per the schedule you've set.&lt;/p&gt;

&lt;p&gt;For API specifications or how to make API calls, you can further explore the following resources:&lt;a href="https://github.com/bitkub/bitkub-official-api-docs"&gt;Bitkub&lt;/a&gt; , &lt;a href="https://www.binance.com/en/binance-api"&gt;Binance&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>serverless</category>
      <category>crypto</category>
    </item>
  </channel>
</rss>
