DEV Community

Akbar Nafisa
Akbar Nafisa

Posted on

Create Access Key for AWS S3

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

Next, choose the service as S3.

Image description

Now, input the following policy into the text editor:

Image description

{
    "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/*"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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

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

Create New User Credential

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

Image description

Enter the User name, then click the Next button.

Image description

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

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

Image description

Create Access Keys

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

Image description

For the first step, choose the other option.

Image description

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

Image description

Finally, click Download .csv file and then Done.

Image description

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

Top comments (0)