Create Access Key for AWS S3
Tags: webdev, javascript, aws, devops
Published: 2023-12-29 00:00:00

Before setting up the GitHub action, it's important to generate an Access Key for uploading files to the designated bucket. To do so, let’s follow this steps

## **Create S3 Access Policy**

Navigate to the `Policies` page and select **`Create policy`** to add a new policy for our bucket.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1u7vnl7hr7ggv3xwrkv.png)

Next, choose the service as S3.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmbk0iewoc4sanfkqweo.png)

Now, input the following policy into the text editor:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kr8gigevw3ljzg4fajly.png)



```json
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "Statement1",
			"Effect": "Allow",
			"Action": [
				"s3:GetObject",
				"s3:PutObject",
				"s3:ListBucket",
				"s3:DeleteObject"
			],
			"Resource": [
			    "arn:aws:s3:::my-awesome-project-bucket",
			    "arn:aws:s3:::my-awesome-project-bucket/*"
			]
		}
	]
}
```

this is the explaination for the config:

- **Action**: Lists the AWS S3 actions allowed by this policy. The allowed actions are:
    - **`s3:GetObject`**: Allowing retrieval of objects from the bucket.
    - **`s3:PutObject`**: Allowing the addition of objects to the bucket.
    - **`s3:ListBucket`**: Allowing the listing of objects within the bucket.
    - **`s3:DeleteObject`**: Allowing the deletion of objects within the bucket.
- **Resource**: Specifies the AWS resources to which the actions apply. In this case, the resources are:
    - **`"arn:aws:s3:::my-awesome-project-bucket"`**: Refers to the bucket.
    - **`"arn:aws:s3:::my-awesome-project-bucket/*"`**: Refers to all objects within the bucket.

To get the `arn` you can copy it from the `properties` section in the bucket page.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvr5mrlnxwv45m113bkx.png)



Once the configuration is complete, click the **`Next`** button, enter a policy name, and click **`Create policy`** at the bottom of the page.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1fv489rcuo48uqpou5g.png)



## **Create New User Credential**

Navigate to the `Users` page in the `IAM` dashboard and click the **`Create user`** button.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/he92wb58ci9r1niqyut4.png)



Enter the **`User name`**, then click the **`Next`** button.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4javmd443azudlymla3v.png)



Select **`Attach policies directly`** in **`Permissions options`** and choose the policy created earlier. Click the **`Next`** button to proceed to the last step.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pl84z3lhpfge52ns37zr.png)



Review the configuration in the last step and click **`Create user`** to finish.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/67s8kf1q1qbdk9e24yld.png)



## **Create Access Keys**

Navigate to the `Users` page, open **`Security credentials`**, and click **`Create access key`** under the **`Access keys`** section.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgbuzrpp1vnh9lp8l27a.png)

For the first step, choose the **`other`** option.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts597qlw7t5r6g7obkgh.png)

In the second step, enter a description for the access key and click the **`Create access key`** button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3z8t0nqbgn4whx21syd.png)

Finally, click **`Download .csv file`** and then **`Done`**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5emv4bv3782yrecxz05p.png)

With this setup completed, we are ready to create an automated update to the S3 bucket using GitHub CI.