<?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>Forem: Alex</title>
    <description>The latest articles on Forem by Alex (@tyrannosauralex).</description>
    <link>https://forem.com/tyrannosauralex</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%2F1235597%2Fc2f17907-8394-4266-90ca-388a5c7ee271.jpeg</url>
      <title>Forem: Alex</title>
      <link>https://forem.com/tyrannosauralex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tyrannosauralex"/>
    <language>en</language>
    <item>
      <title>Guide to Dify 1.1.3 on AWS using docker-compose, connected to Postgres RDS, with TLS through an AWS ALB</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Wed, 09 Apr 2025 05:01:30 +0000</pubDate>
      <link>https://forem.com/tyrannosauralex/guide-to-dify-113-on-aws-using-docker-compose-connected-to-postgres-rds-with-tls-through-an-aws-2aa0</link>
      <guid>https://forem.com/tyrannosauralex/guide-to-dify-113-on-aws-using-docker-compose-connected-to-postgres-rds-with-tls-through-an-aws-2aa0</guid>
      <description>&lt;p&gt;After spending several hours searching the web and tinkering with Dify using docker (more specifically docker-compose) on an EC2 instance, I realized that there are no updated guides to self-hosted Dify on AWS. Or rather, none that replace the default postgres database with RDS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why on earth would I want to connect my Dify to RDS?
&lt;/h2&gt;

&lt;p&gt;Since it is a containerized deployment of Dify, there are plenty of reasons to store your data in RDS. Whenever I want to update Dify, all I have to do is update it in place and my data stored on RDS doesn't disappear on accident. I'm not a veteran engineer or architect, and I am quite aware that accidentally deleting entire knowledge bases from Dify could cause a few headaches. I don't want to spew out the same information as all those AI written posts with fancy buzzwords, but I quite like RDS's high availability, scalability, and easy backups. Even if it does cost a tiny bit of money to run.&lt;/p&gt;

&lt;p&gt;With all of that out of the way, the reason you're probably here is for a guide on how to set it up. So, I will just get straight to it. I will try to keep it extremely simple, as well as cover parts that I believe may trip you up.&lt;/p&gt;




&lt;h2&gt;
  
  
  Guide on how to set it up
&lt;/h2&gt;

&lt;p&gt;Don't expect this guide to cover ever OS and every issue that comes up. I apologize if my way of setting it up causes issues for your specific requirements.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If you are running another app on port 80 or 443, then I explain how to change the dify port below.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Requirements (Skipping AWS account and VPC setup)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An EC2 instance running Amazon Linux 2023 (if not, then this guide may not work for you perfectly)&lt;br&gt;
Note: that the instance type is recommended to be a medium sized instance or larger. I am running different containers on my instance, so I chose a t3.large instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;EBS storage of 25GB or larger. Type gp3 is fine.&lt;br&gt;
Note: 25GB is enough for just Dify. I have a separate instance for my old Dify deployment and it is using 22GB of EBS storage. For my CURRENT t3.large instance I chose 40GB. This allows me to run other containers on EBS without running into strange OOM (Out of memory. Not mana, but I suppose they are the same thing, huh?)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;EC2 instance profile with permissions for EC2 to assume the role (principal: ec2.amazonaws.com, action: sts:AssumeRole) and for whatever permissions may be required in the future for Dify. Example: If you are using Amazon Bedrock, then you will need to give the instance Bedrock permissions or it will fail!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For TLS (newer SSL, HTTPS) connection to your deployment I suggest an application load balancer. If you are deploying for your own specific use, and not for a group of people, then try fiddling around with certbot and letsencrypt. It is included in the docker-compose file we will get from github in a moment.&lt;br&gt;
I won't explain how to set up an ALB and target group, since there are tons of guides online. However, note that the ALB itself will remain listening to ports 80 and 443, but the 443 (TLS) listener's target group should be pointed at port 8080. The port 80 listener on the ALB should redirect traffic to the 443 listener.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Postgres RDS instance, size 20GiB (Could probably be smaller, but the free tier is 20GiB per month!) The security group for the instance must allow ingress on tcp port 5432 from the security group you gave to your EC2 instance! For simplicity of managing your RDS instance you may want to just connect to RDS from your local computer. In that case you'll need to open port 5432 to your local IP as well. This will allow you to manage the databases on the instance using psql or pgadmin.&lt;br&gt;
NOTE: Take a memo of your RDS login information. You have to give it to Dify in the .env file, which I explain down below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Installations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install docker-compose
Optional: First install the new aws cli and ssm if you are going to be using it to pull RDS secrets or variables from secrets manager or parameter store. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install docker, docker-compose, git and update system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;git&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;curl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-L&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/docker/compose/releases/latest/download/docker-compose-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="n"&gt;uname&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="n"&gt;uname&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/usr/local/bin/docker-compose&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change docker-compose permissions and add a user to docker group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;chmod&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/usr/local/bin/docker-compose&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;newgrp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;usermod&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-aG&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;docker&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ec2-user&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Optional, install AWS CLI v2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;unzip&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;remove&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;awscli&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;curl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"awscliv2.zip"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;unzip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;awscliv2.zip&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;/aws/install&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;rm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;awscliv2.zip&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-rf&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ln&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/usr/local/bin/aws&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/usr/bin/aws&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: that last line using "ln" I had to add to link /usr/local/bin/aws to /usr/bin/aws. For some reason when running the aws cli commands it errored without it. So that's my fix.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install dify and set up the DB.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dnf&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-y&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;postgresql15-server&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;PGPASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"(INSTERT YOUR RDS INSTANCE PASSWORD HERE)"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;createdb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-h&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;INSERT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;YOUR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;RDS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;DATABASE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ENDPOINT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;HERE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;5432&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-U&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;INSERT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;YOUR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;USERNAME&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;HERE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dify&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Don't include the parenthesis around the "INSERT..." sections. For example, PGPASSWORD="mypassword"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone the repository
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;clone&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;https://github.com/langgenius/dify.git&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If you are experiencing issues with the current release of Dify (such as issues connecting to RDS that won't fix no matter how many times you google the issue) then you may need to downgrade the dify version to the last working version. Use the following command to do so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;checkout&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-b&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;main-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;NUMBER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;HERE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;reds/tags/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;VERSION&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;NUMBER&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;HERE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Set up the .env file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;/home/ec2-user/dify/docker&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;cp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;example&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nx"&gt;sed&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'/EXPOSE_NGINX_PORT=/ s/=.*/=8080/'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="w"&gt; 
&lt;/span&gt;&lt;span class="n"&gt;sed&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'/EXPOSE_NGINX_SSL_PORT=/ s/=.*/=8443/'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: In this example I am changing the port to access Dify to 8080 and 8443 instead of the original 80 (HTTP) and 443 (HTTPS). If that is not a requirement then don't use the sed command above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Changing the docker-compose.yaml file to set up RDS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Within the docker-compose.yaml file there are 3 things we need to change. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;i. Comment out the "db" block using #&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt; &lt;span class="c1"&gt;# The postgres database.&lt;/span&gt;
 &lt;span class="c1"&gt;# db:&lt;/span&gt;
 &lt;span class="c1"&gt;#   image: postgres:15-alpine&lt;/span&gt;
 &lt;span class="c1"&gt;#   restart: always&lt;/span&gt;
 &lt;span class="c1"&gt;#   environment:&lt;/span&gt;
 &lt;span class="c1"&gt;#     PGUSER: ${PGUSER:-postgres}&lt;/span&gt;
 &lt;span class="c1"&gt;#     POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-difyai123456}&lt;/span&gt;
 &lt;span class="c1"&gt;#     POSTGRES_DB: ${POSTGRES_DB:-dify}&lt;/span&gt;
 &lt;span class="c1"&gt;#     PGDATA: ${PGDATA:-/var/lib/postgresql/data/pgdata}&lt;/span&gt;
 &lt;span class="c1"&gt;#   command: &amp;gt;&lt;/span&gt;
 &lt;span class="c1"&gt;#     postgres -c 'max_connections=${POSTGRES_MAX_CONNECTIONS:-100}'&lt;/span&gt;
 &lt;span class="c1"&gt;#              -c 'shared_buffers=${POSTGRES_SHARED_BUFFERS:-128MB}'&lt;/span&gt;
 &lt;span class="c1"&gt;#              -c 'work_mem=${POSTGRES_WORK_MEM:-4MB}'&lt;/span&gt;
 &lt;span class="c1"&gt;#              -c 'maintenance_work_mem=${POSTGRES_MAINTENANCE_WORK_MEM:-64MB}'&lt;/span&gt;
 &lt;span class="c1"&gt;#              -c 'effective_cache_size=${POSTGRES_EFFECTIVE_CACHE_SIZE:-4096MB}'&lt;/span&gt;
 &lt;span class="c1"&gt;#   volumes:&lt;/span&gt;
 &lt;span class="c1"&gt;#     - ./volumes/db/data:/var/lib/postgresql/data&lt;/span&gt;
 &lt;span class="c1"&gt;#   healthcheck:&lt;/span&gt;
 &lt;span class="c1"&gt;#     test: [ 'CMD', 'pg_isready' ]&lt;/span&gt;
 &lt;span class="c1"&gt;#     interval: 1s&lt;/span&gt;
 &lt;span class="c1"&gt;#     timeout: 3s&lt;/span&gt;
 &lt;span class="c1"&gt;#     retries: 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But why?&lt;br&gt;
Because, this sets up a local postgres database. Which we don't need, because we are connecting our dify to RDS.&lt;/p&gt;

&lt;p&gt;ii. Comment out the "depends on: db" sections of the worker, api, and plugin daemon services. Each section has something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;#    depends_on:&lt;/span&gt;
 &lt;span class="c1"&gt;#     - db&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only comment out the - db for the api and worker, but comment out the depends_on block for the plugin daemon.&lt;/p&gt;

&lt;p&gt;iii. Add SSL required to the plugin daemon (the last line in this block):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;plugin_daemon&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;langgenius/dify-plugin-daemon:0.0.6-local&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Use the shared environment variables.&lt;/span&gt;
      &lt;span class="na"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;*shared-api-worker-env&lt;/span&gt;
      &lt;span class="na"&gt;DB_DATABASE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${DB_PLUGIN_DATABASE:-dify_plugin}&lt;/span&gt;
      &lt;span class="na"&gt;DB_SSL_MODE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${DB_SSL_MODE:-require}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But why? Because without it your RDS connection will error when you run Dify.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up the .env file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever vector store you use is up to you. If you want to keep the default as weviate then just leave the .env vector store section alone, however you can set up pgvector to be used with RDS, so I will explain how shortly below. However, note that I am not a master at vector stores and have never used pgvector besides this one single time. Do your own research on vector stores and make an informed decision.&lt;/p&gt;

&lt;p&gt;First and foremost, what the heck is a vector?&lt;br&gt;
A vector embedding is, simply put, numbers that correlate to meanings of sentences, words, etc. A vector store stores those numbers, and allows us to search for not only matches to words, sentences, etc. but also the meanings of them. So in Dify, when we give it a knowledge base, it stores that knowledge and the meanings in a vector store. Then, when we ask it a question it will search for the meaning in the vector store. &lt;/p&gt;

&lt;p&gt;On to the pgvector setup:&lt;/p&gt;

&lt;p&gt;To set up RDS to use a vector store, you should run this command on the RDS instance, using psql or query it in pgadmin.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="n"&gt;EXTENSION&lt;/span&gt; &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once finished, open .env in your favorite file editor and change the following variables to match whatever you want it to be. However, note that the default pgvector DB is the same name as the dify database default name we gave it, "dify". You should be able to safely use the same database name, since the vector store and the dify db store entirely different data. We just use the pgvector extension to allow our DB to handle vector embeddings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VECTOR_STORE=pgvector

PGVECTOR_HOST=(RDS ENDPOINT HERE)
PGVECTOR_PORT=5432
PGVECTOR_USER=(RDS USERNAME HERE)
PGVECTOR_PASSWORD=(RDS PASSWORD HERE)
PGVECTOR_DATABASE=dify (CAN CHANGE IF YOU MAKE A NEW DB)
PGVECTOR_MIN_CONNECTION=1
PGVECTOR_MAX_CONNECTION=5
PGVECTOR_PG_BIGM=false
PGVECTOR_PG_BIGM_VERSION=1.2-20240606
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to give the .env file our RDS information for our normal Dify DB (not the vector store, but the one that stores user data and the such):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_USERNAME=(RDS USERNAME HERE)
DB_PASSWORD=(RDS PASSWORD HERE)
DB_HOST=(RDS ENDPOINT HERE)
DB_PORT=5432(THE PORT TO RDS HERE)
DB_DATABASE=dify(THE NAME OF YOUR DB HERE)
DB_SSL_MODE=require
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You should add the DB_SSL_MODE=require line underneath the already existing DB variables!!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start up Dify
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;docker-compose&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;docker-compose.yaml&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;up&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You may need to provide the path to the docker-compose.yaml file. The -f flag is used to tell docker-compose the path to the file. Also, the -d flag is used to tell docker-compose to continue running it in the background. Without it, you'll have to stare at the docker container running in your terminal all day to keep it alive.&lt;/p&gt;

&lt;p&gt;Congratulations on making it this far. I pray that your Dify deployment worked the first time. Be careful though, you should check your docker-compose logs to see if there are any errors occurring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;docker-compose&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;docker-compose.yaml&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;logs&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;The most common errors in my experience are DB related errors. If you get an error saying "no encryption" for the connection to your RDS instance, then that means something is wrong with the SSL require line we added above (DB_SSL_MODE=require and DB_SSL_MODE: ${DB_SSL_MODE:-require}).&lt;/p&gt;

&lt;p&gt;If you run into any strange errors that don't necessarily point at much, try checking the memory or storage of the instance. Check the ebs volume using &lt;code&gt;df -hT&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you have an OOM message when trying to run docker-compose up -d, then you either need to increase EBS size or delete old images you aren't using for docker. This can be done by running:&lt;br&gt;
&lt;code&gt;docker image prune -a -f&lt;/code&gt;&lt;br&gt;
You could also try pruning old volumes:&lt;br&gt;
&lt;code&gt;docker volume prune -f&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For more troubleshooting help, feel free to comment and if I can then I will try to help find the cause. &lt;/p&gt;

&lt;p&gt;If you have any questions, concerns, or tips then please leave them in the comments as well! As I stated before, I am a new engineer with only half a year under my belt.&lt;/p&gt;

</description>
      <category>dify</category>
      <category>aws</category>
      <category>ai</category>
      <category>rds</category>
    </item>
    <item>
      <title>From English Teacher to AWS Architect</title>
      <dc:creator>Alex</dc:creator>
      <pubDate>Mon, 06 May 2024 09:21:40 +0000</pubDate>
      <link>https://forem.com/tyrannosauralex/from-english-teacher-to-aws-architect-a2h</link>
      <guid>https://forem.com/tyrannosauralex/from-english-teacher-to-aws-architect-a2h</guid>
      <description>&lt;p&gt;Hello! &lt;br&gt;
My name is Alex Day. My path to AWS might seem a little unconventional. After studying Cyber Security at the University of Texas at San Antonio, to the surprise of my family, I found myself teaching English in Japan. Last year, I decided to make a career shift and set my sights on becoming a Cloud Security Architect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For those of you that just want to see what I used to pass the exam, scroll down until you see STOP in bold!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Three months of dedicated studying later, I was celebrating passing the AWS Certified Solutions Architect - Associate exam!  Looking back, a big part of my success came from the hands-on experience I gained with Adrian Cantrill's AWS courses.  These courses, along with the valuable AWS documentation, provided the perfect one-two punch for my learning journey.&lt;/p&gt;

&lt;p&gt;Cantrill's labs played an instrumental part in learning and passing the exam (&lt;a href="https://github.com/acantril/learn-cantrill-io-labs" rel="noopener noreferrer"&gt;https://github.com/acantril/learn-cantrill-io-labs&lt;/a&gt;). They not only allowed me to get my hands dirty building cool projects in the AWS environment, but also gave me something to show on my github to prove my abilities to future recruiters. This practical experience solidified my understanding of the theoretical concepts I was reading about in the AWS documentation.&lt;/p&gt;

&lt;p&gt;For those that are already further along in your AWS studies, I suggest trying to tackle his &lt;strong&gt;Advanced Demo - Web App - Single Server to Elastic Evolution&lt;/strong&gt;! It takes a single Wordpress server and turns it into a fully elastic, scalable and resistant architecture. &lt;/p&gt;

&lt;h2&gt;
  
  
  STOP!!
&lt;/h2&gt;

&lt;p&gt;Here's my full list of things I did to pass the exam:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adrian Cantrill's AWS courses AND labs&lt;br&gt;
&lt;a href="https://learn.cantrill.io" rel="noopener noreferrer"&gt;https://learn.cantrill.io&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tutorials Dojo practice exams&lt;br&gt;
&lt;a href="https://tutorialsdojo.com" rel="noopener noreferrer"&gt;https://tutorialsdojo.com&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Quizlet - To remember specific facts about services &lt;a href="https://quizlet.com" rel="noopener noreferrer"&gt;https://quizlet.com&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notebook after notebook&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While some may disagree that using a notebook while studying tech takes too long, but....&lt;br&gt;
The pen is a slower instrument than the keyboard, but its very slowness can be a virtue. It forces us to &lt;strong&gt;&lt;em&gt;think&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;organize&lt;/em&gt;&lt;/strong&gt; our thoughts before we commit them to paper.&lt;/p&gt;

&lt;p&gt;Maybe you are like me, and can only remember things that you committed to paper. &lt;br&gt;
With that, I wish you luck on your studies and AWS building! I am off to study Terraform and automate the building of a Minecraft server.&lt;/p&gt;

&lt;p&gt;See you next time,&lt;br&gt;
Alex.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>learning</category>
      <category>cloudcomputing</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
