<?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:  Khem Sok</title>
    <description>The latest articles on DEV Community by  Khem Sok (@khemsok).</description>
    <link>https://dev.to/khemsok</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%2F1002153%2F012106be-9f0c-4393-ab59-699b21ded454.jpeg</url>
      <title>DEV Community:  Khem Sok</title>
      <link>https://dev.to/khemsok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khemsok"/>
    <language>en</language>
    <item>
      <title>a practical guide to understanding iam policies</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Wed, 28 Jun 2023 23:41:18 +0000</pubDate>
      <link>https://dev.to/khemsok/a-practical-guide-to-understanding-iam-policies-2h17</link>
      <guid>https://dev.to/khemsok/a-practical-guide-to-understanding-iam-policies-2h17</guid>
      <description>&lt;h3&gt;
  
  
  &lt;em&gt;TLDR&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;AWS Identity and Access Management (IAM) policies regulate access to AWS resources. Policies can be attached to identities (users, groups, or roles) or resources. Each policy consists of statements with key elements: Principal, Action, Resource, Effect, and optional Conditions.&lt;/p&gt;

&lt;p&gt;Policies can either be &lt;strong&gt;identity-based&lt;/strong&gt;, attached to an IAM identity, or &lt;strong&gt;resource-based&lt;/strong&gt;, attached directly to a resource. The policy defines permissions for an identity or specifies what actions a principal can perform on a resource.&lt;/p&gt;

&lt;p&gt;Each policy statement has the following elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Principal&lt;/strong&gt;: In identity-based policies, the principal is the attached IAM identity. In resource-based policies, the principal is an entity granted or denied access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Action&lt;/strong&gt;: Defines specific tasks that the policy allows or denies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource&lt;/strong&gt;: Specifies the AWS resource that the policy governs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Effect&lt;/strong&gt;: Can be &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;. If &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;, the principal is permitted to perform the action on the resource unless another policy denies it. If &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;, it overrides any &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Condition&lt;/strong&gt; (optional): Specifies any conditions for the policy statement to take effect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Policies are evaluated as follows: an explicit &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt; overrides any &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;. If there's no explicit &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;, an explicit &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; permits the request. If neither &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; nor &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt; is present, the request is denied by default.&lt;/p&gt;

&lt;p&gt;Principals in a policy can be of different types, including &lt;strong&gt;&lt;code&gt;AWS&lt;/code&gt;&lt;/strong&gt; for IAM users or roles, &lt;strong&gt;&lt;code&gt;Service&lt;/code&gt;&lt;/strong&gt; for AWS services, &lt;strong&gt;&lt;code&gt;Federated Users&lt;/code&gt;&lt;/strong&gt; for federated identities, &lt;strong&gt;&lt;code&gt;Anonymous&lt;/code&gt;&lt;/strong&gt; for unauthenticated access, and &lt;strong&gt;&lt;code&gt;AWS Organizations&lt;/code&gt;&lt;/strong&gt; for the entire organization or an organizational unit (OU).&lt;/p&gt;

&lt;p&gt;The blog post includes numerous examples of IAM policies with different conditions, multiple principals, and different principle types to demonstrate the flexibility and complexity of IAM policy creation. Remember, the key rule in IAM policy creation is to grant the least amount of access necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;AWS Identity and Access Management (IAM) policies are the cornerstone of managing access to AWS resources. A policy is an entity that, when attached to an identity or resource, defines their permissions. This blog post will help you understand the core components of IAM policies and the pivotal role they play in AWS's access control capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understanding IAM Policy Types&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are two main types of IAM policies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Identity-based policies:&lt;/strong&gt; These policies attach to an IAM identity (a user, group, or role). They control what actions the identity can perform, on which resources, and under what conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource-based policies:&lt;/strong&gt; These policies attach directly to a resource. They define what actions a specified principal (which could be in another account) can perform on that resource.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Deep Dive into IAM Policy Components&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;IAM policies are composed of one or more statements, and each statement includes these elements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Principal:&lt;/strong&gt; In an identity-based policy, the principal is the IAM identity to which it's attached. In a resource-based policy, the principal is the entity that is allowed or denied access to the resource. The principal can be specified as a single string or a list of strings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Action:&lt;/strong&gt; This is the specific task the policy allows or denies. For instance, &lt;strong&gt;&lt;code&gt;s3:PutObject&lt;/code&gt;&lt;/strong&gt; permits an entity to upload an object to an S3 bucket. Actions can be specified as a single string or a list of strings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource:&lt;/strong&gt; The resource is the specific AWS asset that the policy allows or denies actions upon. Resources are defined using Amazon Resource Names (ARNs), and can be specified as a single string or a list of strings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Effect:&lt;/strong&gt; The effect can be either &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;. If the effect is &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;, the principal is permitted to perform the action on the resource, assuming no other policies deny it. If the effect is &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;, it overrides any &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Condition:&lt;/strong&gt; The condition is an optional field specifying any conditions for the policy statement to take effect. Conditions might include IP address range, time of day, whether MFA is enabled, and more.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;IAM Policy Evaluation Logic&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;IAM employs the following logic to evaluate policies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An explicit &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt; in any policy trumps any &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If there's no explicit &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt;, an explicit &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; in any policy permits the request.&lt;/li&gt;
&lt;li&gt;If neither &lt;strong&gt;&lt;code&gt;Allow&lt;/code&gt;&lt;/strong&gt; nor &lt;strong&gt;&lt;code&gt;Deny&lt;/code&gt;&lt;/strong&gt; is present, the default decision is to deny the request.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Examples of IAM Policies&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Example 1: IAM policy that includes a list for each of these elements:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ExampleStatement"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"AWS"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::123456789012:user/Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::123456789012:user/Bob"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:DeleteObject"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::my_bucket/example1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::my_bucket/example2"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&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;p&gt;This policy grants both Alice and Bob the ability to upload, download, and delete the &lt;strong&gt;&lt;code&gt;example1&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;example2&lt;/code&gt;&lt;/strong&gt; objects in &lt;strong&gt;&lt;code&gt;my_bucket&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: Allow Access Only From Specific IP Addresses&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following IAM policy allows the principal to perform any Amazon S3 action (&lt;strong&gt;&lt;code&gt;s3:*&lt;/code&gt;&lt;/strong&gt;) on the bucket named &lt;strong&gt;&lt;code&gt;my_bucket&lt;/code&gt;&lt;/strong&gt; but only if the request originates from the range of IP addresses specified in the condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::my_bucket/*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"IpAddress"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"aws:SourceIp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"192.0.2.0/24"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&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;p&gt;In this policy, the &lt;strong&gt;&lt;code&gt;aws:SourceIp&lt;/code&gt;&lt;/strong&gt; condition key is used to match the IP address from where the request originates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3: Allow Access Only During Specific Times&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following IAM policy allows the principal to perform any Amazon DynamoDB action (&lt;strong&gt;&lt;code&gt;dynamodb:*&lt;/code&gt;&lt;/strong&gt;) but only during a specific time of day:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dynamodb:*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"DateGreaterThan"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"aws:CurrentTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"09:00:00Z"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"DateLessThan"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"aws:CurrentTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"17:00:00Z"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&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;p&gt;In this policy, the &lt;strong&gt;&lt;code&gt;aws:CurrentTime&lt;/code&gt;&lt;/strong&gt; condition key is used to allow requests only between 09:00:00 UTC and 17:00:00 UTC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 4: Allow Access Only With MFA&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This IAM policy allows deleting an Amazon S3 bucket (&lt;strong&gt;&lt;code&gt;s3:DeleteBucket&lt;/code&gt;&lt;/strong&gt;) but only if the requester is using multi-factor authentication (MFA):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:DeleteBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Bool"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"aws:MultiFactorAuthPresent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&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;p&gt;In this policy, the &lt;strong&gt;&lt;code&gt;aws:MultiFactorAuthPresent&lt;/code&gt;&lt;/strong&gt; condition key is used to check whether the request was made using MFA.&lt;/p&gt;

&lt;p&gt;Remember, conditions provide an additional layer of security to control when and who can use the actions granted in your IAM policies. By understanding and leveraging conditions, you can greatly enhance the security of your AWS resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A Note on IAM Principles&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In an AWS IAM policy, the &lt;strong&gt;&lt;code&gt;Principal&lt;/code&gt;&lt;/strong&gt; element identifies the user, account, service, or other entity allowed or denied access to a resource. Here are different types of principals:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;AWS:&lt;/strong&gt; Specifies an AWS account, IAM user, IAM role, federated user, or assumed-role user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service:&lt;/strong&gt; Allows AWS services to act on a resource.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Federated Users:&lt;/strong&gt; Used for identities federated into AWS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anonymous:&lt;/strong&gt; The wildcard "*" allows unauthenticated access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS Organizations:&lt;/strong&gt; Specifies the entire organization or an organizational unit (OU).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember to grant only the minimum necessary permissions to maintain security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Example 1: AWS Principle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a resource-based policy that grants an IAM user in another AWS account the permission to read objects from an S3 bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"GrantReadAccess"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"AWS"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::123456789012:user/Alice"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::my_example_bucket/*"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&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;p&gt;&lt;strong&gt;Example 2: Service Principle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a resource-based policy that allows the EC2 service to assume a role:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ec2.amazonaws.com"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&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;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;IAM policies form the backbone of AWS's access control capabilities. They can be complex, so taking the time to understand the different elements and principles is essential for managing AWS resources securely and effectively. Always remember the guiding rule of granting the least amount of access necessary to perform a function. It's a crucial step in maintaining the security of your AWS infrastructure.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>iam</category>
    </item>
    <item>
      <title>automate notion and todoist: a guide to syncing your to-do list with lambda and webhooks 🔥</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Mon, 24 Apr 2023 01:39:51 +0000</pubDate>
      <link>https://dev.to/khemsok/automate-notion-and-todoist-a-guide-to-syncing-your-to-do-list-with-lambda-and-webhooks-2cl6</link>
      <guid>https://dev.to/khemsok/automate-notion-and-todoist-a-guide-to-syncing-your-to-do-list-with-lambda-and-webhooks-2cl6</guid>
      <description>&lt;h3&gt;
  
  
  Introductions 👨‍💻
&lt;/h3&gt;

&lt;p&gt;I use Notion to keep track of all my todos inside of a database. However, if you’re on your phone, Notion doesn’t provide an easy way for user to easily add todos into the database without clicking multiple things and the loading takes annoyingly forever. This is where Todoist comes in. I can easily click on the app and press the plus button and it will create a todo for me. However, I don’t want to use two applications to track the same thing, so I wanted to sync my Todoist with Notion. &lt;/p&gt;

&lt;p&gt;I see that there are automations existed already with applications like &lt;code&gt;Zapier&lt;/code&gt; but there are limitations to it. So I thought I could go ahead and automate the system myself. And this blog aims to help out others who want to do the same.&lt;/p&gt;

&lt;h4&gt;
  
  
  Requirements
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You will need to have an AWS account for this tutorial as we will be creating a Function URL with AWS Lambda. (Don’t worry it won’t cost you anything, you will not exceed the Free Tier)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Todoist and Notion both have APIs that we can use have them sync with each and it is not hard to work with at all. &lt;/p&gt;

&lt;h5&gt;
  
  
  Step 1
&lt;/h5&gt;

&lt;p&gt;Head to Notion API and create a new integration: &lt;a href="https://www.notion.so/my-integrations" rel="noopener noreferrer"&gt;https://www.notion.so/my-integrations&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%2Fb1jf9hlhi9o1w9sube2w.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%2Fb1jf9hlhi9o1w9sube2w.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 2
&lt;/h5&gt;

&lt;p&gt;Copy the &lt;code&gt;Internal Integration Token&lt;/code&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%2F0zjvos9d8zp9k6irgc7q.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%2F0zjvos9d8zp9k6irgc7q.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 3
&lt;/h5&gt;

&lt;p&gt;Copy the &lt;code&gt;Notion Database ID&lt;/code&gt; that you want to create the task in. You can get the &lt;code&gt;Notion Database ID&lt;/code&gt; by heading to Notion online and view the database as a full page and in the URL, you will see the database ID. &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%2Fcn3wj2p5x8u5uye9llvc.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%2Fcn3wj2p5x8u5uye9llvc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 4
&lt;/h5&gt;

&lt;p&gt;You need to allow your database to connect with the Notion Integration that we just created&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%2Fve93kdjth97t7q5h4g4m.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%2Fve93kdjth97t7q5h4g4m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 5
&lt;/h5&gt;

&lt;p&gt;Head to AWS console and Create a Python Lambda Function&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%2Fqrm7vo4u3vntty6lui61.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%2Fqrm7vo4u3vntty6lui61.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to choose &lt;code&gt;Python 3.9&lt;/code&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%2F0bf59qjtgri2k1q14g5t.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%2F0bf59qjtgri2k1q14g5t.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 6
&lt;/h5&gt;

&lt;p&gt;Create Function URL and select Auth type as NONE&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%2F440s4pgyjg0mxh1ugzwu.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%2F440s4pgyjg0mxh1ugzwu.png" alt="Image description"&gt;&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%2Fv9tjri8kkf2k314g6ouh.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%2Fv9tjri8kkf2k314g6ouh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 7
&lt;/h5&gt;

&lt;p&gt;Add Layer to the Lambda&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%2F3wpp26gxtwlyguxybb10.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%2F3wpp26gxtwlyguxybb10.png" alt="Image description"&gt;&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%2Fvy12pz2vkgx81s5vw2fn.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%2Fvy12pz2vkgx81s5vw2fn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 8
&lt;/h5&gt;

&lt;p&gt;Copy the following code. You will need to change three things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the &lt;code&gt;Internal Integration Token&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add the &lt;code&gt;Notion Database ID&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add the field name of your database where you want the task name to be. E.g Name&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then deploy it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import requests

url = "https://api.notion.com/v1/pages"
headers = {
    "Authorization": "Bearer &amp;lt;Internal Integration Token&amp;gt;",
    "Content-Type": "application/json",
    "Notion-Version": "2022-06-28"
}

def lambda_handler(event, context):
    content = json.loads(event['body'])['event_data']['content']

    data = {
        "parent": {
            "type": "database_id",
            "database_id": "&amp;lt;Notion Database Id&amp;gt;"
        },
        "properties": {
            "&amp;lt;field name your database for title&amp;gt;": {
                "type": "title",
                "title": [
                    {
                        "type": "text",
                        "text": {
                            "content": content
                        }
                    }
                ]
            }
        }
    }


    response = requests.post(url, headers=headers, data=json.dumps(data))

    return {
        'statusCode': 200,
        'body': 'success',
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F3953rem5awz23b2923t0.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%2F3953rem5awz23b2923t0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we have done so far is create a Lambda Function that will create an item in the database whenever it gets called by Todoist Webhook. &lt;/p&gt;

&lt;p&gt;Now we have to configure Todoist for it to make a make a request to that Function whenever there is a new item created.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 9
&lt;/h5&gt;

&lt;p&gt;Head to Todoist Developer console to create a new app: &lt;a href="https://developer.todoist.com/appconsole.html" rel="noopener noreferrer"&gt;https://developer.todoist.com/appconsole.html&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%2Fbewp5oik4l5l4329h3yh.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%2Fbewp5oik4l5l4329h3yh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 10
&lt;/h5&gt;

&lt;p&gt;Go back to our Lambda and copy our Function URL. Paste it in the Webhook callback url in Todoist App. Also select the &lt;code&gt;item:added&lt;/code&gt; Watched Events. Then click on &lt;code&gt;Activate webhook&lt;/code&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%2Fq5xtik2oql52xrise3mk.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%2Fq5xtik2oql52xrise3mk.png" alt="Image description"&gt;&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%2Fgsoz09riu7dj2y6h9zcf.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%2Fgsoz09riu7dj2y6h9zcf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 11&lt;/p&gt;

&lt;p&gt;So Webhook doesn’t activate by default until we complete OAuth process with the account. For more information here: &lt;a href="https://developer.todoist.com/sync/v8/#webhooks" rel="noopener noreferrer"&gt;https://developer.todoist.com/sync/v8/#webhooks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First add the OAuth redirect URL as our Function URL in the Todoist App&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%2F1dt5g9b27ag486xhj4zi.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%2F1dt5g9b27ag486xhj4zi.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to complete the OAuth process for the account. Below are two CURL command, but you can do it with Postman or other HTTP clients as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl "https://todoist.com/oauth/authorize?client_id=&amp;lt;client_id&amp;gt;&amp;amp;scope=data:read&amp;amp;state=secretstring"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F9kfwj105magonk6ok5bx.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%2F9kfwj105magonk6ok5bx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the link and follow the instruction and it should redirect you to the Function URL. DO NOT close out of this tab as the URL will have the code that we need.&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%2Fz47l0nygkwfmg7ulzksy.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%2Fz47l0nygkwfmg7ulzksy.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl "https://todoist.com/oauth/access_token" \
    -d "client_id=&amp;lt;client_id&amp;gt;" \
    -d "client_secret=&amp;lt;client_secret&amp;gt;" \
    -d "code=&amp;lt;code received from the first curl command&amp;gt;" \
    -d "redirect_uri=&amp;lt;function url&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all. Now whenever you create an item inside of your Todoist, it will create a row inside of your Notion database.&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%2F925gzgnwoof7ygmcj45u.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%2F925gzgnwoof7ygmcj45u.png" alt="Image description"&gt;&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%2Fl17jb0y63x7m4wtunvr9.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%2Fl17jb0y63x7m4wtunvr9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion 🎯
&lt;/h4&gt;

&lt;p&gt;Hope this helps you guys out. Let me know if you have any questions ✌️&lt;/p&gt;

</description>
      <category>automation</category>
      <category>lambda</category>
      <category>productivity</category>
      <category>notion</category>
    </item>
    <item>
      <title>how taking cold shower everyday landed me amazon and microsoft offers 👨‍💻</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Sun, 12 Mar 2023 18:40:17 +0000</pubDate>
      <link>https://dev.to/khemsok/how-taking-cold-shower-everyday-landed-me-amazon-and-microsoft-offers-2hp7</link>
      <guid>https://dev.to/khemsok/how-taking-cold-shower-everyday-landed-me-amazon-and-microsoft-offers-2hp7</guid>
      <description>&lt;p&gt;this is not an article articulating the technical details of how i prepared for my microsoft and amazon interview, but rather how i built the necessary habits and mindset going into my preparation.&lt;/p&gt;

&lt;p&gt;as you are reading this, you may be thinking to yourself, how does taking a cold shower have anything to do with getting a tech job offer. in my case, it played a major role. the action of taking a cold shower itself does not directly influence my success during the interview itself, however, it impacted on a larger scale which is the foundation on how i was able to build up a mindset that allows me to go about executing a routine that i had to follow on a daily basis leading up to the interview. that directly influenced how i was able to successfully construct a plan, act on it, and lead me to acing the interviews.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“preparation are keys”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;i hate the cold and the feeling of being cold. i am the type of person that has a space heater nearby and uses a hand warmer at the office. i very much despise and detest cold showers. so this begs the question of why do it? for the simple reason, to make myself uncomfortable. after i finished reading can’t hurt me and man’s search for meaning, i just spontaneously decided one night that i am going to take a cold shower.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“do the things you don’t like” - david goggins&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;i remember the first time thinking that it was not too bad. although, while in the shower, i was shaking uncontrollably and afterward i had cold feet for hours. but i remember thinking it was not too bad. the feeling of accomplishment of doing something difficult was enough to combat the uncomfortableness. i kept at it, once in the morning and once at night. gradually, i increased the time i stayed in the shower from 5 minutes all the way to 10 minutes in the first week. the first few days went well, i was actually excited to do this task because the dopamine afterward was worth it. however after the first week, the task started to become increasingly more cumbersome and it dawned on me that i do not want to be doing this. the fear of taking cold showers starts to creep in as my mind poisons with the thought of having to stand through the freezing cold droplets of water for 10 minutes. delaying, stalling, procrastinating became the name of the game. i would stand in front of my shower door for minutes thinking why the hell am i doing this. i absolutely hated it. i hate being cold during it and afterward. all these thoughts would run through my brain, but i do it anyway. every single time for the first 2.5 months, i would question myself “why am i doing this? i could be enjoying a hot shower right now”, but once i set the timer on my phone, i immediately jump into the shower and go through the ordeal. and every single time i got out of it feeling accomplished. this one small change that i added to my routine helps establish the foundation of how i go about building up my discipline.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“consistent actions everyday will lead to result overtime”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;building habits are very difficult. you can be very motivated to go to the gym for the first few days, but over time that motivation dissipates. when that happens, what is there to rely on? discipline. that is the lesson that i’ve learnt from taking cold showers everyday. the understanding that no matter how annoying and uncomfortable the task of a cold shower is i will do it anyway. that very thought process in itself is very powerful. the thing with discipline is it can be trained like a muscle. once your discipline muscle is leveling up, you are more inclined to do things that make you uncomfortable. this led me to discovering the “no days off” framework where there are certain things that i will do everyday no matter what. these include meditating (&amp;gt;5 mins), reading (25 mins), playing an instrument (25 mins), journaling (25 mins), planning the next day (25 mins) and studying (50 mins).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“think about how good you will get in 4-5 years if you were to do this task every single day no matter what”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;once the routine had been established, it was not very hard to adapt it to preparing for the interview. with the new found mindset, i was more capable of handling difficult and complex tasks that i do not want to do. it helps me tremendously in persevering through failing to solve easy questions on leetcode in the first few weeks. no matter how hard it is, i told myself i will have to spend x amount of minutes on it each day. i did not want to overwhelm myself too much so i started off at around 15 minutes. bit by bit, i started to see improvements in my ability to solve problems. as the problems get easier, i started to increase the intensity of my routine as i need to go wide and try to solve as many problems as i can to spot the different patterns. solving technical coding challenges is just one aspect of the interview, but the same concepts applied to those other areas as well. my after work hours and weekends were consumed with my preparation. every day, week, and month was planned out on what areas and materials that i need to be focusing on. this allows me to have a clear picture of what i need to be doing at all times so i won’t waste time thinking about what i need to do.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“1% improvement every single day will compound you to a 3800% improvement in one year. ”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;you have to understand that you will not transform yourself overnight, it will take months, or maybe years. but understand this, if you keep at it and grind every single day, you will get to wherever you want to go. you have to trust the process and have the belief that what you are doing right now will lead you to your goal. visualize it, dream it, feel it.&lt;/p&gt;

&lt;p&gt;i was not perfect along the way. there were days where i wasn’t being as productive as i would like to be. there were days where i did a problem just to say i did that problem. there were a lot of days where i wasted time procrastinating. there were days where i wanted to take a break and quit the “no days off”. i am definitely still learning and trying to become better myself. i constantly have to remind myself that this is a marathon, not a sprint. you cannot rush this process. the one thing that helps keep me in check is to remember my goals and the why. understanding and remembering that i am on a journey to better myself is a refresher that i sometimes need to push myself to do my work out at 12 am in the morning or study for an extra pomodoro.&lt;/p&gt;

&lt;p&gt;the lessons that i learnt along the way are huge. i get a sense that i understand myself better and the tendencies that i would partake in. for example, i’d get distracted by watching a youtube clip and i would go on a tangent for about 10-15 minutes before i realized that i need to stop and do the tasks that i set out for. things like that i would realize and find ways to combat it like using a blocker to block out sites during focus time. i started to see the tendency of my energy level during the day so i tried to maximize my time during those peak energy levels. it was definitely very fun to experiment with different routines such as eating habits, sleeping routine, and journal about it and see what i can do to tweak it to better maximize my productivity. and as i kept up with the routine every single day, i started to have this sense of belief that i’ll do very well in the interview. i wasn’t 100% confident going into the interview but i knew that with either outcome i was going to be fine with it because i did everything that i could to prepare for it.&lt;/p&gt;

&lt;p&gt;in conclusion, i want to emphasize this point, i am not special by any means of the imagination. i truly believe anyone can absolutely do this. you have the power to change your life at this very second. create a plan, design a schedule and execute on it no matter what. every decision you make can steer you toward your goals. it’s hard, but not impossible. consistent hard work will get you to where you want to go, building that mindset is the goal. i hope you guys enjoy the article.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;this article was written a while back when i first joined aws, but i just never posted it anywhere. thought to share my experience here : )&lt;/em&gt;&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>productivity</category>
    </item>
    <item>
      <title>writing clean and maintainable code: best practices for developers 🦉</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Mon, 20 Feb 2023 00:06:30 +0000</pubDate>
      <link>https://dev.to/khemsok/writing-clean-and-maintainable-code-best-practices-for-developers-5724</link>
      <guid>https://dev.to/khemsok/writing-clean-and-maintainable-code-best-practices-for-developers-5724</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fp86u0yzsyjx8tqzyllzt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fp86u0yzsyjx8tqzyllzt.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  intro
&lt;/h2&gt;

&lt;p&gt;writing code is one thing, but writing clean and maintainable code is another. clean and maintainable code is essential for developing successful applications that are easy to maintain, improve, and scale over time. in this article, we'll cover some best practices for writing clean and maintainable code that you can use to take your development skills to the next level.&lt;/p&gt;

&lt;h4&gt;
  
  
  follow good naming conventions
&lt;/h4&gt;

&lt;p&gt;the first step to writing clean code is to follow naming conventions. use meaningful and descriptive names for your variables, functions, and classes. avoid using abbreviations or acronyms unless they're widely recognized. use camelCase or snake_case for naming variables and functions, and use PascalCase for naming classes.&lt;/p&gt;

&lt;h4&gt;
  
  
  keep it simple stupid (kiss)
&lt;/h4&gt;

&lt;p&gt;when writing code, keep it simple stupid. write code that is easy to understand and that is easy to read. avoid writing long and complex functions, which can be challenging to understand and maintain. if a function is too long, consider splitting it into smaller, more manageable functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  dont repeat yourself (dry)
&lt;/h4&gt;

&lt;p&gt;one of the most essential principles of writing clean and maintainable code is to avoid repetition. if you find yourself writing the same code in multiple places, consider extracting it into a separate function or class. this will not only make your code more concise, but it will also make it easier to maintain.&lt;/p&gt;

&lt;h4&gt;
  
  
  write tests
&lt;/h4&gt;

&lt;p&gt;writing tests is an essential part of writing clean and maintainable code. ensure that your tests cover all the critical parts of your code, and that they're easy to understand and maintain.&lt;/p&gt;

&lt;h4&gt;
  
  
  refactor regularly
&lt;/h4&gt;

&lt;p&gt;refactoring is the process of improving your code without changing its functionality. regularly refactoring your code ensures that it remains clean and maintainable over time. refactor long functions, remove redundant code, and improve variable names. this process will help keep your codebase up-to-date and ensure that it remains easy to maintain. always leave code better than when you found it&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;writing clean and maintainable code is an essential skill for developers. following these best practices can help you to write code that is easy to understand, maintain, and scale over time.&lt;/p&gt;

</description>
      <category>devmeme</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>mastering git: the only essential commands you need to know to be a productive developer [pt 2] 🔥</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Sun, 12 Feb 2023 02:27:47 +0000</pubDate>
      <link>https://dev.to/khemsok/mastering-git-the-only-essential-commands-you-need-to-know-to-be-a-productive-developer-pt-2-3doo</link>
      <guid>https://dev.to/khemsok/mastering-git-the-only-essential-commands-you-need-to-know-to-be-a-productive-developer-pt-2-3doo</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fc9nrwkxnc8ntxk3px1xb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fc9nrwkxnc8ntxk3px1xb.png" alt="Image description" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  intro
&lt;/h3&gt;

&lt;p&gt;this article is pt 2 of the mastering git series. see part 1 &lt;a href="https://dev.to/khemsok/mastering-git-the-only-essential-commands-you-need-to-know-to-be-a-productive-developer-pt-1-1pjd"&gt;here&lt;/a&gt;. in this article, we will expand on those commands and introduce 7 additional git commands that are useful to your workflow.&lt;/p&gt;

&lt;h4&gt;
  
  
  8 - &lt;code&gt;git status&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command displays the status of your local repository, including the changes that have been staged, changes that have been made but not stage, and untracked file.&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="nv"&gt;$ &lt;/span&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  9 - &lt;code&gt;git diff&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command displays the difference between two snapshots of your repository. you can use it to see the changes you've made in your local repository compared to the remote repository, changes between different branches, or changes between different commits.&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="nv"&gt;$ &lt;/span&gt;git diff HEAD &lt;span class="c"&gt;# to compare the current branch with the latest commit&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git diff branch1 branch2 &lt;span class="c"&gt;# to compare two branches&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  10 - &lt;code&gt;git fetch&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to retrieve changes from a remote repository, but it does not integrate them into your local repository. you can use it to see what changes have been made to a remote repository without affecting your local copy of the 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="nv"&gt;$ &lt;/span&gt;git fetch origin &lt;span class="c"&gt;# to fetch changes from the "origin" remote repository&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  11 - &lt;code&gt;git stash&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to save changes that haven't been committed or staged to a temporary location. this can be useful if you need to switch to a different branch without having to commit.&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="nv"&gt;$ &lt;/span&gt;git stash &lt;span class="c"&gt;# to stash changes&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git stash save &lt;span class="s2"&gt;"comment"&lt;/span&gt; &lt;span class="c"&gt;# to save stash in the repository&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git stash list &lt;span class="c"&gt;# to list all stashes&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git stash pop &lt;span class="c"&gt;# to reapply previously stashed changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  12 - &lt;code&gt;git merge&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command allows you to combine changes from different branches into a single branch.&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="nv"&gt;$ &lt;/span&gt;git merge branch-name &lt;span class="c"&gt;# to merge changes from a branch named "branch-name" into the current branch&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git merge branch-name &lt;span class="nt"&gt;--squash&lt;/span&gt; &lt;span class="c"&gt;# to merge changes from a branch named "branch-name" into the current branch without bringing in the commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  13 - &lt;code&gt;git log&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command displays a log of all of the commits in your git repository. you can use it to see the history of your project and find specific commits&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="nv"&gt;$ &lt;/span&gt;git log &lt;span class="c"&gt;# to display the log of all commits&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;-5&lt;/span&gt; &lt;span class="c"&gt;# to display last 5 commits&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  14 - &lt;code&gt;git rebase&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command allows you to reapply a series of commits from one branch onto another branch. this is useful for reorganizing the history of a branch to make it more readable.&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="nv"&gt;$ &lt;/span&gt;git rebase origin main &lt;span class="c"&gt;# to reapply the commits from the branch origin main onto the current branch&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  conclusion
&lt;/h3&gt;

&lt;p&gt;here are additional seven git commands that is essential to your git workflow. hope you guys find this useful. thx.&lt;/p&gt;

</description>
      <category>gratitude</category>
      <category>motivation</category>
      <category>community</category>
    </item>
    <item>
      <title>mastering git: the only essential commands you need to know to be a productive developer [pt 1] 🔥</title>
      <dc:creator> Khem Sok</dc:creator>
      <pubDate>Sun, 05 Feb 2023 21:28:25 +0000</pubDate>
      <link>https://dev.to/khemsok/mastering-git-the-only-essential-commands-you-need-to-know-to-be-a-productive-developer-pt-1-1pjd</link>
      <guid>https://dev.to/khemsok/mastering-git-the-only-essential-commands-you-need-to-know-to-be-a-productive-developer-pt-1-1pjd</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2F0oaaa5isfasbfgpndc8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F0oaaa5isfasbfgpndc8b.png" alt="Image description" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  intro
&lt;/h3&gt;

&lt;p&gt;git is something all programmers have used or will use one way or another. with its vast number of commands and options, it can be overwhelming for someone that is just starting out. learn these few essential commands and you'll be 80% there with your journey with git.&lt;/p&gt;

&lt;h4&gt;
  
  
  1 - &lt;code&gt;git init&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used initialize a new git repository. it creates a .git folder wehre all of the version control information is stored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init &lt;span class="c"&gt;# to initialize a repository&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2 - &lt;code&gt;git clone&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to clone an existing repository from a remote server to your local machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/user/repo.git &lt;span class="c"&gt;# to clone a repository&lt;/span&gt;

git clone https://github.com/user/repo.git another-repo-name &lt;span class="c"&gt;# to clone a repository and give it a different local name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3 - &lt;code&gt;git add&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to add changes to the staging area.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="c"&gt;# to add all changes in the current directory&lt;/span&gt;

git add file.txt &lt;span class="c"&gt;# to add changes in a specific file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4 - &lt;code&gt;git commit&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to save changes to the repository. the changes can be a single file or multiple files. when you run git commit, you'll be prompted to write a commit message to describe the changes you've made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"commit message"&lt;/span&gt; &lt;span class="c"&gt;# to commit changes with a message directly from the command line&lt;/span&gt;

git commit &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="c"&gt;# to commit all changes in the repository&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5 - &lt;code&gt;git push&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to push changes from your local to a remote repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin main &lt;span class="c"&gt;# to push changes to the remote repository named "origin" and the branch named "main"&lt;/span&gt;

git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main &lt;span class="c"&gt;# to set the upstream branch for "origin/main" to "main"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6 - &lt;code&gt;git pull&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to retrieve changes from a remote repository and merge them into your local repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin main &lt;span class="c"&gt;# to get changes from the remote repository named "origin" and the branch named "main"&lt;/span&gt;

git pull &lt;span class="nt"&gt;--rebase&lt;/span&gt; &lt;span class="c"&gt;# to reapply your local changes on top of the changes in the remote repository&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  7 - &lt;code&gt;git checkout&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;this command is used to switch between different branches in the repository. branches allow you to work on different version of the project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; new-branch &lt;span class="c"&gt;# to create a new branch named "new-branch" and switch to it&lt;/span&gt;

git checkout branch-name &lt;span class="c"&gt;# to switch to an existing branch named "branch-name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  conclusion
&lt;/h3&gt;

&lt;p&gt;these are the seven essential git commands that you need to get started. mastering these command, and you'll be on your way to become a git expert. &lt;/p&gt;

</description>
      <category>devto</category>
      <category>announcement</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
