title: I need to implement a file upload feature so that any user could upload a file in AWS S3 bucket from frontend. My project is in Typescript Language
body: <p>I have achieved it by using the AWS credentials embedded in the code. But this is not good practice ..could someone suggest another way to do that maybe by using IAM role or assume role.</p>
  <p>Code for receiving  the file from frontend</p>
  <pre><code>&lt;Grid item xs={12} className={classes.field}&gt;
          &lt;Typography variant=&quot;h6&quot;&gt;
              6. If File Not Present In S3 buket then First Upload The File In S3
            &lt;/Typography&gt;
              &lt;DropzoneArea
                acceptedFiles={['.csv']}
                //acceptedFiles={['image/*']}
                dropzoneText={&quot;Drag and drop an .csv file here&quot;}
                dropzoneClass={classes.dropZone}
                useChipsForPreview={true}
                filesLimit={1}
                ////maxFileSize={200000}
                //fileObjects=fileObjects
                onChange={(files) =&gt;  setFileList(files)} 
              /&gt;
              &lt;Button
                  size=&quot;large&quot;
                  type=&quot;submit&quot;
                  color=&quot;primary&quot;
                  variant=&quot;contained&quot;
                  endIcon={&lt;FiUpload /&gt;}
                  onClick={handleFileUploadSubmit}
                &gt;
                  Upload File In S3
                &lt;/Button&gt;
            &lt;/Grid&gt;
  </code></pre>
  <p>Passing the file object and further below is the code for uploading the file in AWS using credentials embeeded in code-</p>
  <pre><code>import S3 from 'react-aws-s3';
  import {
      errorAlertWithoutTimer,
      successAlert,
    } from '../../sweetAlerts/SweetAlerts'
  window.Buffer = window.Buffer || require(&quot;buffer&quot;).Buffer;
  
  const config = {
      bucketName: '',
      region: '',
      accessKeyId: '',
      secretAccessKey: '',
      s3Url: '',
  }
  
  
  
  
  
  export const  uploadFileInAws= (file: any) =&gt; {
      const ReactS3Client = new S3(config);
      console.log(file,file.name)
      ReactS3Client
      .uploadFile(file, file.name)
      .then(successAlert('Success', 'File Upload SuccessFully Queued'))
      .catch(err =&gt; console.error(err))
  
    }
  </code></pre>