<?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: Dmitry Kankalovich</title>
    <description>The latest articles on DEV Community by Dmitry Kankalovich (@dmitrykankalovich).</description>
    <link>https://dev.to/dmitrykankalovich</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%2F631081%2Fba3d88b8-9b1d-4de3-87b1-06caa244b613.jpeg</url>
      <title>DEV Community: Dmitry Kankalovich</title>
      <link>https://dev.to/dmitrykankalovich</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dmitrykankalovich"/>
    <language>en</language>
    <item>
      <title>Transform Notion into RSS reader with AWS Lambda and AWS CDK</title>
      <dc:creator>Dmitry Kankalovich</dc:creator>
      <pubDate>Wed, 19 May 2021 14:25:54 +0000</pubDate>
      <link>https://dev.to/dmitrykankalovich/transform-notion-into-rss-reader-with-aws-lambda-and-aws-cdk-4kcp</link>
      <guid>https://dev.to/dmitrykankalovich/transform-notion-into-rss-reader-with-aws-lambda-and-aws-cdk-4kcp</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: we are going to build a customized RSS reader on the basis of Notion using Notion API beta and AWS Lambda. See the source code &lt;a href="https://github.com/dzmitry-kankalovich/notion-rss-feed/tree/v1" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3p2gvzbxe45d69s42kp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3p2gvzbxe45d69s42kp.png" alt="High-level architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As of May 13th, the &lt;a href="https://www.notion.so/" rel="noopener noreferrer"&gt;Notion&lt;/a&gt; had released a public beta preview of their API. This is a long-awaited feature that enables you to further consolidate your activities in one single tool. One particular thing which I always wanted Notion to provide is the integration for my daily RSS feed.&lt;/p&gt;

&lt;p&gt;While Notion itself doesn’t have anything out-of-the-box for pulling in your RSS feed, the release of Notion API is something that provides us with the opportunity to leverage a myriad of automation platforms as well as serverless solutions from Cloud providers to implement whatever integration we want.&lt;/p&gt;

&lt;h1&gt;
  
  
  Before we start
&lt;/h1&gt;

&lt;p&gt;You should know that there are several decent RSS readers like &lt;a href="https://feedly.com/" rel="noopener noreferrer"&gt;Feedly&lt;/a&gt; which do a fine job of aggregating your RSS feeds, so before jumping the gun I recommend checking them out.&lt;/p&gt;

&lt;h1&gt;
  
  
  Choosing the automation platform
&lt;/h1&gt;

&lt;p&gt;Another thing which you might want to check out is the &lt;a href="https://automate.io/" rel="noopener noreferrer"&gt;automate.io&lt;/a&gt;. This is one of many automation platforms which promises you to do what you need in just a few clicks.&lt;/p&gt;

&lt;p&gt;There is indeed an advertised RSS integration with Notion which I went to test out — only to realize that it’s just not good enough for me. There seems to be a lack of configurability, like the ability to set up multiple RSS feeds, as well as be able to tune trigger logic.&lt;/p&gt;

&lt;p&gt;However, we still can build what we need using a bit lower level abstraction — serverless function platforms like AWS Lambda or Azure Functions.&lt;/p&gt;

&lt;p&gt;I personally was working with AWS for years and often use it as a platform for my personal projects, so here I’d go with that option. However, there are no AWS-exclusive specifics in the problem we’re about to solve, so any serverless function platform would work for you just fine.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisite
&lt;/h1&gt;

&lt;p&gt;Here is the list of required stuff before moving forward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NodeJS&lt;/strong&gt; of version 14+ (comes with its package manager &lt;strong&gt;NPM&lt;/strong&gt; which we’ll need later on)&lt;/li&gt;
&lt;li&gt;An active AWS account.&lt;/li&gt;
&lt;li&gt;AWS IAM user with enough permissions to deploy via CDK and use AWS Lambda — &lt;strong&gt;AdministratorAccess&lt;/strong&gt; policy will be enough. Check out this &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html" rel="noopener noreferrer"&gt;guide&lt;/a&gt; for more details.&lt;/li&gt;
&lt;li&gt;AWS CLI configured with that user credentials — &lt;strong&gt;Access Key ID&lt;/strong&gt; and &lt;strong&gt;Access Key Secret&lt;/strong&gt;. See this &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html" rel="noopener noreferrer"&gt;guide&lt;/a&gt; for examples on how to do it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure you’ve explicitly exported the AWS profile with these credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;% &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;AWS_PROFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;AWS CDK will check this variable by default to figure out which account it works with and what IAM user permissions it should leverage.&lt;/p&gt;
&lt;h1&gt;
  
  
  The AWS Part
&lt;/h1&gt;

&lt;p&gt;While you can do all of the needed AWS changes and configurations by hand clicking through AWS Console, I usually go with the infra-as-a-code (IaaC) approach, so I am going to stick with that here.&lt;/p&gt;

&lt;p&gt;AWS CDK is a relatively new way to provision your infrastructure following IaaC even more literally than Cloudformation / Terraform did before — using a programming language like Typescript to create AWS resources.&lt;/p&gt;

&lt;p&gt;I will use AWS CDK here, but you can again achieve the same results with other IaaC options like Cloudformation, Terraform, and others.&lt;/p&gt;

&lt;p&gt;| You will be able to find all source code &lt;a href="https://github.com/dzmitry-kankalovich/notion-rss-feed/tree/v1" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deploy your AWS CDK app
&lt;/h2&gt;

&lt;p&gt;If you never worked with AWS CDK before — no worries, it’s all fairly simple. I recommend checking out this &lt;a href="https://github.com/aws/aws-cdk#getting-started" rel="noopener noreferrer"&gt;document&lt;/a&gt;. Assuming that you have installed &lt;code&gt;node&lt;/code&gt; of at least version &lt;strong&gt;14+&lt;/strong&gt; run the following snippet:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;% npm i &lt;span class="nt"&gt;-g&lt;/span&gt; aws-cdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next, create your project directory and init the CDK project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~ % &lt;span class="nb"&gt;mkdir &lt;/span&gt;notion-rss-feed &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;
notion-rss-feed % cdk init sample-app &lt;span class="nt"&gt;--language&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As you can see — we explicitly specify the language as &lt;code&gt;typescript&lt;/code&gt;. There are many other languages supported for the CDK, however, with Typescript, you'd be able to find most examples for as well as it being the first-class citizen language for the CDK, since all others are just wrappers.&lt;/p&gt;

&lt;p&gt;Assuming &lt;code&gt;cdk init&lt;/code&gt; ran without problems you should get the following structure:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % tree &lt;span class="nt"&gt;-L&lt;/span&gt; 1
&lt;span class="nb"&gt;.&lt;/span&gt;
├── README.md
├── bin
├── cdk.json
├── jest.config.js
├── lib
├── node_modules
├── package-lock.json
├── package.json
├── &lt;span class="nb"&gt;test&lt;/span&gt;
└── tsconfig.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;There is quite a number of files, but don’t worry — you don’t need to deal with most of them. The part you’d be looking into is in the lib folder - all the resource stack definitions will go there. By convention, CDK will create a single file there named &lt;code&gt;notion-rss-feed-stack.ts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So let’s go ahead and modify our Stack at &lt;code&gt;lib/notion-rss-feed-stack.ts&lt;/code&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;There are no resources defined just yet. It’s fine, we’ll add them later and for now, let’s just deploy this stack to verify we are able to perform such operation for your AWS Account.&lt;/p&gt;

&lt;p&gt;First, bootstrap the environment (you need to do it only once per AWS account, and might not need to do it if you’ve been using CDK before):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % cdk bootstrap &lt;span class="nt"&gt;--profile&lt;/span&gt; your-aws-profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then — deploy our resource stack:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output should look like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NotionRssFeedStack: deploying...
NotionRssFeedStack: creating CloudFormation changeset...
[██████████████████████████████████████████████████████████] (2/2)
 ✅  NotionRssFeedStack
Stack ARN:
arn:aws:cloudformation:us-east-1:69924*******:stack/NotionRssFeedStack/f6b61890-b4a3-11eb-a371-1266a0dd9289
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You’re now all set for the actual development!&lt;/p&gt;

&lt;p&gt;| If you see &lt;code&gt;Unable to resolve AWS account to use&lt;/code&gt;. then check out &lt;a href="https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_prerequisites" rel="noopener noreferrer"&gt;this doc&lt;/a&gt; for the guidance on how to configure deployment target account and associated &lt;code&gt;Access Key ID&lt;/code&gt; / &lt;code&gt;Access Key Secret&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create Lambda function
&lt;/h2&gt;

&lt;p&gt;Let’s create a Lambda function that will pull the specified RSS feed and push it to the Notion. We’re going to put lambda code in a separate folder:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; resources/lambda
notion-rss-feed % &lt;span class="nb"&gt;cd &lt;/span&gt;resources/lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Initialize the &lt;strong&gt;NPM&lt;/strong&gt; project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lambda % npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And then add all the needed dependencies:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lambda % npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; rss-parser @notionhq/client dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Finally, add a Lambda handler code. Create index.js with the following contents:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Obviously, this is not the final version of the Lambda function, but something we can use for now to implement a proof of concept solution and then gradually improve upon.&lt;/p&gt;

&lt;p&gt;Let’s get back to our resource Stack and create an actual Lambda function resource in AWS.&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;lib/notion-rss-feed-stack.ts&lt;/code&gt; and add Lambda provision code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;If &lt;code&gt;@aws-cdk/aws-lambda&lt;/code&gt; cannot be resolved - explicitly add the respective NPM package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @aws-cdk/aws-lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And now we should be good to deploy our Lambda:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The CDK would ask you to confirm the creation of the IAM Role needed for the Lambda execution. Proceed with y as your answer and see the stack update progress. Finally, once deployment completed, you should be able to see the ARN of our Lambda function:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Outputs:
NotionRssFeedStack.NotionRssFeedHandlerName = NotionRssFeedStack-NotionRssFeedHandler4C3C1ED2-WD0IieIRVroG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Your exact Lambda name is always account-specific and will differ a little bit from mine, so be sure to copy the one that you actually see in your CDK deploy output.&lt;/p&gt;

&lt;p&gt;Let’s use provided function name to test that Lambda function:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % aws lambda invoke &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--function-name&lt;/span&gt; NotionRssFeedStack-NotionRssFeedHandler4C3C1ED2-WD0IieIRVroG &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--payload&lt;/span&gt; &lt;span class="s1"&gt;'{}'&lt;/span&gt; lambda_output.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cat &lt;/span&gt;lambda_output.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The output should look like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"StatusCode"&lt;/span&gt;: 200,
    &lt;span class="s2"&gt;"ExecutedVersion"&lt;/span&gt;: &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LATEST&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="s2"&gt;"The AWS Cloud platform expands daily. Learn about announcements, launches, news, innovation and more from Amazon Web Services."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This last line indicates that our Lambda had been successfully executed and had pulled in RSS feed of the AWS latest news. With this output verified we’re now officially halfway through.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Notion Part
&lt;/h1&gt;

&lt;p&gt;We need to prepare Notion before we can actually start sending the RSS content. Essentially we need to do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a so-called &lt;strong&gt;Private integration&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Create a parent page or database to hold all our daily RSS entries&lt;/li&gt;
&lt;li&gt;Share that page or database with our integration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;| The above steps are also described &lt;a href="https://developers.notion.com/docs/getting-started" rel="noopener noreferrer"&gt;here&lt;/a&gt; in much greater detail, so if you’re having troubles understanding the context — check it out.&lt;/p&gt;

&lt;p&gt;But before — let’s figure out exactly what we are going to do with respect to displaying RSS entires in Notion. I see there are three ways to achieve what we need, and I am going to walk through all of them.&lt;/p&gt;
&lt;h3&gt;
  
  
  Option 1. Database
&lt;/h3&gt;

&lt;p&gt;We can create a Notion database, define some schema for properties and add items as child pages — a page per RSS item. This approach would allow us to supply rich content for every page (aka RSS entry), like a textual preview of the feed item.&lt;/p&gt;

&lt;p&gt;However, there are some considerable drawbacks that stem from Notion API limitations at the moment. These are the inability to clean up the database or delete the particular page. With no ability to clean up before every integration run, it means that the database would likely pile up duplicated pages.&lt;/p&gt;
&lt;h3&gt;
  
  
  Option 2. Page with nested table
&lt;/h3&gt;

&lt;p&gt;The idea here is to establish a regular Notion page with a nested table, which we can simply delete at the beginning of each integration run and re-create with RSS items. However, at the moment Notion API beta does not allow you to work with tables.&lt;/p&gt;
&lt;h3&gt;
  
  
  Option 3. List with links to the RSS items
&lt;/h3&gt;

&lt;p&gt;Finally, we can establish a root page to serve as a table of contents and create a child page for every integration run (with a page title of current date), and for that given child page simply create a bulleted list of links. We won’t have any preview apart of the link name — RSS item title, but in many cases that will be enough. &lt;strong&gt;This is the variant we’re going with here&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create Integration
&lt;/h2&gt;

&lt;p&gt;Assuming you’re the owner or admin of your workspace, simply click &lt;strong&gt;Settings &amp;amp; Members&lt;/strong&gt; → &lt;strong&gt;Integrations&lt;/strong&gt; → &lt;strong&gt;Develop your own integrations&lt;/strong&gt; → &lt;strong&gt;New integration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Give it some meaningful name, upload an RSS icon, and finally hit &lt;strong&gt;Submit&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now open the integration we’ve just created and grab &lt;strong&gt;Internal Integration Token&lt;/strong&gt; — we’ll need it later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fco1suzph177raved5ns5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fco1suzph177raved5ns5.png" alt="Integration page"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create RSS page
&lt;/h2&gt;

&lt;p&gt;Next — create a place to store RSS items in Notion. For that create a new page, set the title &lt;strong&gt;RSS&lt;/strong&gt;, and that’s pretty much it for the page layout. Later on, our integration will be creating here child pages with RSS content inside, and the RSS page — as long as it’s empty — will display all the children pages as a sort of table of contents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fea88ghy3uirwwdgmjh7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fea88ghy3uirwwdgmjh7m.png" alt="Simple page to ingest RSS feed"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Share RSS page with integration
&lt;/h2&gt;

&lt;p&gt;The last thing for the Notion part — allow our integration actually access the page we’ve just created. So go ahead select our RSS page, hit &lt;strong&gt;Share → Invite → Select your integration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8wpax92wouuiqwg4m0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk8wpax92wouuiqwg4m0y.png" alt="Share screen&amp;lt;br&amp;gt;
"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Relaying RSS feed to the Notion API
&lt;/h1&gt;

&lt;p&gt;Switch back to the code repo. We’re about to start sending RSS items to the Notion API. For that, we need to pass the integration token to Lambda. I strongly advise against hardcoding it, and rather suggest putting it in &lt;code&gt;.env&lt;/code&gt; file. Simply create &lt;code&gt;.env&lt;/code&gt; file at the root of the project and fill it with the following entries:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NOTION_INTEGRATION_TOKEN=&amp;lt;your notion integration token value&amp;gt;
NOTION_PAGE_NAME=RSS
RSS_FEED_URL=https://aws.amazon.com/about-aws/whats-new/recent/feed/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can replace the page name and RSS feed URL with values of your choice, however, bear in mind that &lt;code&gt;NOTION_PAGE_NAME&lt;/code&gt; should have the &lt;strong&gt;exact&lt;/strong&gt; page name, which you've created in the previous step. Later on, we'll use the Notion API Search endpoint to find your page unique ID.&lt;/p&gt;

&lt;p&gt;Let’s now update &lt;code&gt;lib/notion-rss-feed-stack.ts&lt;/code&gt; with these config values:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;You can see that we simply pass these values as-is via environment variables.&lt;/p&gt;

&lt;p&gt;Finally, the Lambda handler code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And that’s pretty much it for the Lambda part. Deploy it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And check it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % aws lambda invoke &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--function-name&lt;/span&gt; NotionRssFeedStack-NotionRssFeedHandler4C3C1ED2-WD0IieIRVroG &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--payload&lt;/span&gt; &lt;span class="s1"&gt;'{}'&lt;/span&gt; lambda_output.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cat &lt;/span&gt;lambda_output.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;| Again, don’t forget to provide your own specific &lt;code&gt;function-name&lt;/code&gt; found in the CDK deploy output.&lt;/p&gt;

&lt;p&gt;If everything is good — you should be able to see your daily RSS feed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2prbxwt33k2ihgefkz7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2prbxwt33k2ihgefkz7k.png" alt="RSS feed example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So every time you invoke Lambda, a page with the current date gets created and lists all the RSS items in it, linking out to the respective pages.&lt;/p&gt;
&lt;h1&gt;
  
  
  Scheduling RSS feed
&lt;/h1&gt;

&lt;p&gt;We’ve got our RSS feed in Notion! However, we don’t want to manually use AWS CLI every day, so let’s go ahead and schedule our Lambda to be executed on a daily basis automatically.&lt;/p&gt;

&lt;p&gt;For that, we will use AWS EventBridge, which provides the capability to define CRON expression for triggering Lambda.&lt;/p&gt;

&lt;p&gt;First, need to add some related dependencies. Switch to the project root and run the following:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @aws-cdk/aws-events @aws-cdk/aws-events-targets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next — create an event rule and make it invoke Lambda on schedule. Edit &lt;code&gt;lib/notion-rss-feed-stack.ts&lt;/code&gt; as follows:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Pay attention to the cron expression — you should set it to value that works for you. In my case, I’ve set it to trigger Lambda every day at 5:30 am UTC. You can read more about AWS cron expressions &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Deploy our changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;notion-rss-feed % cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this concludes our sample implementation.&lt;/p&gt;

&lt;p&gt;| As I said in the beginning, you may find the final version of the sources &lt;a href="https://github.com/dzmitry-kankalovich/notion-rss-feed/tree/v1" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  What’s left
&lt;/h1&gt;

&lt;p&gt;There are many areas to improve upon which I didn’t cover here for the sake of simplicity, but you’re welcome to take on that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As we’re using only a Beta version of Notion API, more features are expected to come over time: deletion, tables, maybe even HTML or Markdown support. Those will open the opportunity to build a more sophisticated solution, ideally, the one that allows to actually preview content.&lt;/li&gt;
&lt;li&gt;The security of the solution is not ideal — Integration Token is stored in plain text in Lambda environment variable. If there is anyone else using this AWS account, you should secure tokens using something like AWS Secrets Manager.&lt;/li&gt;
&lt;li&gt;There is just one single RSS endpoint we’re using here. We can expand the solution to aggregate several endpoints.&lt;/li&gt;
&lt;li&gt;AWS is not a particularly friendly place for personal projects, so I typically establish some monitoring and alarms to make sure some mistake in deployment (say — error in cron expression resulting in much more frequent Lambda invocations) won’t cost me a fortune.&lt;/li&gt;
&lt;li&gt;Keeping RSS config committed to the repo, albeit as a part of the config file, is nice, but not as nearly nice as be able to configure it on the fly with some sort of simple UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For now — that’s it!&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this guide, and if there is going to be enough interest — I’ll do the second part, where we will address some of the mentioned issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Originally published on &lt;a href="https://medium.com/geekculture/transform-notion-into-rss-reader-with-aws-lambda-and-aws-cdk-bc91c5fdc8d3" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>notion</category>
      <category>lambda</category>
      <category>cdk</category>
    </item>
  </channel>
</rss>
