AWS ABC

The goal of this tutorial page is trying to make a user-friendly introduction to AWS

AWS account root users and IAM users

AWS has two types of users, account root user and IAM user.  You are either the account owner (root user) or you are an AWS Identity and Access Management (IAM) user. The root user is created when the AWS account is created. IAM users are created by the root user or an IAM administrator for the account. All AWS users have security credentials. 

Root user credentials

The credentials of the account owner allow full access to all resources in the account. You can't use IAM policies to explicitly deny the root user access to resources. You can only use an AWS Organizations service control policy (SCP) to limit the permissions of the root user of a member account. Because of this, we recommend that you create an IAM user with administrator permissions to use for everyday AWS tasks and lock away the access keys for the root user.

There are specific tasks that can be performed only by the root user. For example, only the root user can close your account. If you need to perform a task that requires the root user, sign in to the AWS Management Console using the email address and password of the root user. For more information, see Tasks that require root user credentials.

IAM credentials

With IAM, you can securely control access to AWS services and resources for users in your AWS account. For example, if you require administrator-level permissions, you can create an IAM user, grant that user full access to your account, and then use those credentials to interact with AWS. If you need to modify or revoke your permissions, you can delete or modify the policies that are associated with that IAM user.

If you have multiple users that require access to your AWS account, create unique credentials for each user and define who has access to which resources. You don't need to and shouldn't share credentials. For example, you can create IAM users with read-only access to resources in your AWS account and distribute the credentials for each IAM user to one of your users.

The above are from this link (with minor rewording): https://docs.aws.amazon.com/accounts/latest/reference/root-user-vs-iam.html

AWS ARN

Amazon Resource Names (ARNs) uniquely identify AWS resources. We require an ARN when you need to specify a resource unambiguously across all of AWS, such as in IAM policies, Amazon Relational Database Service (Amazon RDS) tags, and API calls.

ARN follow the following naming conventions

arn:partition:service:region:account-id:resource-id

arn:partition:service:region:account-id:resource-type/resource-id

arn:partition:service:region:account-id:resource-type:resource-id

ARNs are delimited by colons, and composed of segments, which are the parts separated by colons (:). The specific components and values used in the segments of an ARN depend on which AWS service the ARN is for. Sometimes, some segments in ARN is omitted and therefore you can see something like:

arn:partition:::resource-type/resource-id

See here for more details: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

Connecting S3 - EC2

There are three things one needs to note about connecting S3-EC2. 

Port forwarding  using IPTABLES

nginx reverse proxy seems not working. It turns out that using iptables to map the port 80 to 8501 works well.  That is, do the following command on the instance that you started streamlit. 

sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 8501

Request SSL certificate

openssl req -nodes -newkey rsa:2048 -sha256 -keyout YOUR_SERVER_NAME.key -out YOUR_SERVER_NAME.csr -subj "/C=US/ST=New Jersey/L=Princeton/O=Your Organization/OU=Division of Your Organization/CN=YOUR_SERVER_NAME"

AWSCLI

First, go to ~/.aws/ and edit the credentials file. In the credentials file, you need to enter

[default]

aws_access_key_id=YOUR_ID

aws_secret_access_key=YOUR KEY

aws_session_token=YOUR TOKEN


aws s3 ls

To list details of a s3 bucket, type:

aws s3 ls s3://your-bucket-name

To copy files from local to s3

aws s3 cp my-local-file s3://your-bucket-name

To copy files between s3 buckets

aws s3 cp s3://bucket1/files s3://buckt2/

To copy files from s3 to local

aws s3 cp s3://bucket/files .

Note: sync is recommended over cp.

More commands, please see this link: https://www.bluematador.com/learn/aws-cli-cheatsheet

JSON Policy File

Access and permission in AWS is defined by the JSON policy file. The file is made of one or more statement segments. 

Example JSON policy file is as follows

{

  "Version": "2012-10-17",

  "Statement": [{

    "Sid": "1",

    "Effect": "Allow",

    "Principal": {"AWS": ["arn:aws:iam::account-id:root"]},

    "Action": "s3:*",

    "Resource": [

      "arn:aws:s3:::mybucket",

      "arn:aws:s3:::mybucket/*"

    ]

  }]

}

For more details, see here: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html