<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sam Xzo  on Medium]]></title>
        <description><![CDATA[Stories by Sam Xzo  on Medium]]></description>
        <link>https://medium.com/@sam.xzo.developing?source=rss-5f9b16854b79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ib6vosndf4vRH62n</url>
            <title>Stories by Sam Xzo  on Medium</title>
            <link>https://medium.com/@sam.xzo.developing?source=rss-5f9b16854b79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:05:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sam.xzo.developing/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create AWS IAM user]]></title>
            <link>https://medium.com/@sam.xzo.developing/create-aws-iam-user-02ee9c65c877?source=rss-5f9b16854b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/02ee9c65c877</guid>
            <dc:creator><![CDATA[Sam Xzo ]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 06:01:46 GMT</pubDate>
            <atom:updated>2023-10-16T06:01:46.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2dOTTwuvZGaiiI0Jhj5TeA.png" /></figure><p>Amazon Web Services Identity and Access Management (IAM) is a crucial component for securing your AWS resources. IAM allows you to manage access to your AWS services and resources securely. In this article, we’ll explore how to create programmatic users, add policies to control their permissions and create normal users with console access.</p><h4><strong>Understanding AWS IAM</strong></h4><p>Before diving into user creation and policy assignment, it’s essential to understand some fundamental concepts of AWS IAM:</p><p><strong>1. Users</strong></p><p>Users are entities you create in AWS IAM to represent the people or services that interact with AWS resources. These users have a name and security credentials (either a password for console access or access keys for programmatic access).</p><p><strong>2. Groups</strong></p><p>Groups are collections of IAM users. You can attach policies to groups, which makes it easier to manage permissions for multiple users at once.</p><p><strong>3. Policies</strong></p><p>Policies are JSON documents that define what actions are allowed or denied on AWS resources. You can attach policies to users, groups, or roles.</p><p><strong>4. Roles</strong></p><p>Roles are similar to users but intended for AWS services that need to interact with other AWS services on your behalf. They don’t have passwords or access keys but are assumed by trusted entities.</p><p><strong>5. Access Keys</strong></p><p>Access keys consist of an access key ID and a secret access key. They are used for programmatic access to AWS services, and it’s essential to keep them secure.</p><h4><strong>Creating a User</strong></h4><p>To create an IAM user, please follow the steps below:</p><p><strong>Log in to your AWS Management Console.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*RQIqccIVtNyuaVpv4o5eww.png" /><figcaption>AWS Console Home</figcaption></figure><p><strong>Navigate to the IAM service.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*H5XmXuEWPaG4XCMm67hq2w.png" /><figcaption>Select IAM Service</figcaption></figure><p><strong>In the IAM dashboard, select “Users” from the left-hand menu.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Zs30YsLtw0dVAVENvpIcQA.png" /><figcaption>IAM Dashboard</figcaption></figure><p><strong>Click the “Create user” button.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjKzk569Dtxk8uFTOKZ97g.png" /><figcaption>Users List</figcaption></figure><p><strong>Enter a username for the new IAM user.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ycJgblb5txfNnM85WWjv4g.png" /><figcaption>Create a user</figcaption></figure><p>In this process, if you wish to create a user with access to the AWS Management Console, you must enable the checkbox that provides access to the console. However, if you do not need access to the console and only require a programmatic user, you can leave the checkbox disabled and proceed with the other steps.</p><p><strong>Set permissions for the user by adding them to one or more IAM groups or attaching policies directly.</strong></p><p>Here, I’ll attach a policy directly as follows. When you choose to attach a policy directly, you’ll see a list of predefined policies. You can select one or more policies based on your specific requirements. In this example, I will attach the “Access to S3” policy, which grants the user access to AWS S3 features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*szq3t1W49y4GMdgOWdZG8Q.png" /><figcaption>Set Permission</figcaption></figure><p>If you’re not satisfied with the predefined policies or they don’t match your specific requirements, you have the option to create a custom policy by clicking the “Create policy” button. This way, you can define a policy that aligns with your exact needs.</p><p><strong>Review the user’s details and permissions, then click “Create user.”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*iItvs6l8rRNLJfRIaZL9ZA.png" /><figcaption>Review user</figcaption></figure><p>These steps will create an IAM user with the specified access and permissions.</p><p><strong>Enable console access and Generate Access key.</strong><br>Whether you’ve created a programmatic or console-access user, you’ll find that user’s account listed in the users’ section. By selecting the created user from the list, you can access all the details about that user. In the “Security credentials” tab, there is a section for access keys. From there, you can generate an access key for the user by clicking on the “Create access key” link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9K3K-YlSXEUBNUpjVt13mw.png" /><figcaption>Create access keys</figcaption></figure><p>If someone needs to grant console access as well, they can enable it through the same tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iXJ7thtTT-rloVnMySLJwA.png" /><figcaption>Enable console access</figcaption></figure><p>AWS IAM is a powerful tool for managing access to your AWS resources. By creating programmatic users, adding policies to control their permissions, and creating normal users with console access, you can effectively secure your AWS environment and grant the right level of access to your users. Always follow best practices in IAM to maintain a secure and well-managed AWS environment.</p><p>Remember that security is a top priority in AWS, so always keep your access keys and credentials secure, and regularly review and update your IAM policies as your requirements evolve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02ee9c65c877" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Secure File Download/Upload to AWS S3 with NestJS]]></title>
            <link>https://medium.com/@sam.xzo.developing/implementing-secure-file-download-upload-to-aws-s3-with-nestjs-11144b789c75?source=rss-5f9b16854b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/11144b789c75</guid>
            <dc:creator><![CDATA[Sam Xzo ]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 06:00:47 GMT</pubDate>
            <atom:updated>2023-10-16T06:00:47.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*G33mSElXT2oA7ka-qQTFPQ.jpeg" /></figure><p>Amazon S3 is a powerful and versatile cloud storage service. With S3, you can store objects and retrieve them when needed. There are various ways to upload or download objects to S3, but some methods are less secure. For example, storing AWS Access and Secret keys in the frontend environments and performing uploads directly from there is not recommended.</p><p>Considering this, a better approach is to use pre-signed URLs to enhance the security of object uploads and downloads. Pre-signed URLs provide temporary and controlled access to your S3 objects. In this article, we’ll explore what AWS S3 Pre-signed URLs are and how to use them securely for uploading and viewing objects, particularly with NestJS.</p><h4><strong>What are AWS S3 Pre-signed URLs?</strong></h4><p>AWS S3 Pre-signed URLs are URLs that grant time-limited access permissions to perform specific actions on an S3 object, such as uploading or downloading. These URLs are signed with the access credentials of an IAM (Identity and Access Management) user or a role, and they include information about the allowed actions, the object’s location, and the expiration time. This mechanism provides a secure way to delegate temporary access to S3 resources without revealing your AWS credentials.</p><h4>Generating a Pre-signed URL for Uploading Objects</h4><p><strong>Step 01: Set up AWS SDK or CLI</strong></p><p>Before generating a pre-signed URL, make sure you have the AWS SDK installed or configured the AWS CLI with appropriate credentials.</p><p><strong>Step 02: Include AWS Credentials in the Environment File</strong></p><p>Before proceeding with any actions, it’s advisable to add all the necessary AWS credentials to the .env file. Storing them there enhances security.</p><p><strong>Step 03: Generate a pre-signed URL for uploading an object</strong></p><p>To generate a pre-signed URL for uploading objects, you can utilize AWS SDKs, AWS CLI, or manually craft one using your chosen programming language. In this case, I’m demonstrating a basic example using NestJS, where I’m creating a method to generate a pre-signed URL for uploading an object.</p><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { S3 } from &#39;aws-sdk&#39;;<br><br>@Injectable()<br>export class FileUploadService {<br>    constructor() { }<br><br>    async getPreSignedURL(bucketName: string, key: string, contentType: string) {<br>        const region = process.env.AWS_BUCKET_REGION;<br>        const accessKey = process.env.AWS_ACCESS_KEY;<br>        const secretKey = process.env.AWS_SECRET_KEY;<br><br>        try {<br>            const s3 = new S3({<br>                region: region,<br>                accessKeyId: accessKey,<br>                secretAccessKey: secretKey<br>            });<br><br>            let params = {<br>                Bucket: bucketName,<br>                Key: key,<br>                ContentType: contentType,<br>                Expires: 1800<br>            };<br><br>            return await s3.getSignedUrlPromise(&#39;putObject&#39;, params);<br>        } catch (error) {<br>            throw error;<br>        }<br>    }<br>}</pre><p>When generating a pre-signed URL for uploading an object, we use the `getSignedUrlPromise` method. As its first parameter, we need to specify whether it’s for a `putObject`. Typically, for uploading something, we use “putObject” as this keyword.</p><p>For the second parameter, you should provide the bucket name, the path where you want to save the object, the content type of the object, and finally, the expiration time in seconds. If this request is successful, it will return a URL that allows you to upload a file to S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VpETat5IkvrkIQDJtNp19w.png" /></figure><p>This is how you obtain an upload URL. This pre-signed URL is used for uploading an object, and you can utilize this link to upload your file. To upload a specific file using this URL, you only need to send a PUT request to the provided link while attaching the file in the request body.</p><pre>// this is the URL we got from Backend(Presigned URL)<br>let preSignedURL = &quot;https://s3-tech-talk.s3.amazon............&quot;<br><br>fetch(preSignedURL, {        <br>    body: file,<br>    method: &quot;PUT&quot;,<br>    headers: { &quot;Content-Type&quot;: file.type },<br>});</pre><p>After that, you’ll find your file in that specific bucket.</p><h4>Generating a Pre-signed URL for Viewing Objects</h4><p>Pre-signed URLs can be employed to provide temporary access for viewing (GET) objects in an S3 bucket. Here’s how to generate a pre-signed URL for viewing objects.</p><p>Here as well, we utilize the `getSignedUrlPromise` method on S3, but to view a particular file, you should include the ‘getObject’ keyword as the first parameter. As the second parameter, you need to provide an object that includes the bucket name, folder path where the file is stored on S3, and the expiration time. Once that URL has expired, you will no longer have access to the file.</p><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { S3 } from &#39;aws-sdk&#39;;<br><br>@Injectable()<br>export class FileUploadService {<br>    constructor() { }<br><br>    async getPreSignedURLToViewObject(bucketName: string, key: string) {<br>        const region = process.env.AWS_BUCKET_REGION;<br>        const accessKey = process.env.AWS_ACCESS_KEY;<br>        const secretKey = process.env.AWS_SECRET_KEY;<br><br>        try {<br>            const s3 = new S3({<br>                region: region,<br>                accessKeyId: accessKey,<br>                secretAccessKey: secretKey<br>            });<br><br>            let params = {<br>                Bucket: bucketName,<br>                Key: key,<br>                Expires: 300<br>            };<br><br>            return await s3.getSignedUrlPromise(&#39;getObject&#39;, params);<br>        } catch (error) {<br>            throw error;<br>        }<br>    }<br>}</pre><p>Here, I will demonstrate how it works using Postman. We’ll retrieve a URL to view a file for a limited time, which in this case is 5 minutes. After 5 minutes, that URL will no longer function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9au601HKh19j7GbifjJ9g.png" /></figure><p>Share the generated pre-signed URL with authorized users or systems that need to view the object. They can use this URL to perform a GET request and access the object securely.</p><p>AWS S3 Pre-signed URLs are a powerful mechanism for controlling access to your S3 objects securely. They allow you to delegate temporary permissions for uploading and viewing objects without exposing your AWS credentials. By following the steps outlined in this article, you can easily generate and use pre-signed URLs to enhance the security and flexibility of your AWS S3 storage solutions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11144b789c75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>