1
头图

Because github access is not stable, I think I will migrate my blog to AWS. You can take advantage of the capabilities of AWS storage.

Why choose hexo

  • Generate pages fast
  • support markdown
  • One-click deployment
  • Super extensibility
  • Tons of plugins

Create a blog

 # 安装
npm install hexo-cli -g

# 创建博客
hexo init myblog
cd myblog
npm install

# 本地运行
hexo server

In just a few short steps, the blog was created successfully.

Install deployment tools

 # 安装
npm install hexo-deployer-aws-s3 --save-dev
 # 将部署配置放入 _config.yml
deploy:
  type: aws-s3             # 插件的名字
  region: us-east-1        # 存储桶所在区域
  bucket: my-bucket        # 存储桶名字

AWS Usage Guidelines

Introduction to AWS Storage

S3 is an object storage service that provides industry-leading scalability, data availability, security, and performance. There is 5 GB of free storage space for the first year of use.

Next, we need to create storage on aws.

Create a bucket

after saving

At this point, update the deploy configuration

 # 将部署配置放入 _config.yml
deploy:
  type: aws-s3             # 插件的名字
  region: ap-northeast-1   # 存储桶所在区域
  bucket: robinblog        # 存储桶名字

certificate

The purpose of the credentials is to gain control over the aws s3 storage for deploying static websites. To enter the official documentation , you need to generate credentials, configure policies, and configure credentials.

generate credentials

  1. Sign in to the AWS Management Console and click https://console.aws.amazon.com/iam/ to open the IAM console.
  2. In the navigation pane, choose Users .
  3. Choose the name of the user for which you want to create an access key, and then choose the Security credentials tab.
  4. In the Access keys section, choose Create access key .
  5. To see the new access key pair, choose Show. After closing this dialog, you will no longer be able to access the secret access key. Your credentials are similar to the following:
  • Access Key ID: AKIAIOSFODNN7EXAMPLE
  • Secret Access Key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  1. To download the key pair, choose Download .csv file . Store the key in a safe location. After closing this dialog, you will no longer be able to access the secret access key.
  2. After downloading .csv file, choose Close . When you create an access key, the key pair is active by default and you can use it right away.

After the credentials are generated, you must also have permissions to perform the required IAM actions. For the specific configuration process, please refer to Permissions Required to Access IAM Resources in the IAM User Guide, and the following are the relevant policies I configured

Configure policies

 {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

Configure Credentials

aws provides multiple ways to configure credentials

  1. Loading AWS Identity and Access Management (IAM) roles for Amazon EC2 from
  2. Load from shared credentials file ( ~/.aws/credentials )
  3. Load from environment variables
  4. Load from JSON file on disk
  5. Additional credential-provider classes provided by the JavaScript SDK

I took way 2, load from shared credential file ( ~/.aws/credentials )

 [default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>

Looking at the documentation, you can configure credentials through AWS CLI. The official documentation for installation operations is detailed here . We focus on the process of configuring credentials.

The first installation is successful, the command line execution aws configure configuration is as follows:

After the configuration is successful, the corresponding fields will also be created in the ~/.aws/credentials file

At this point, the configuration is complete.

deploy

`# build
npm run build

deploy

npm run deploy`

Found an error, The bucket does not allow ACLs , also need to open in the storage ACLs

Next, turn off "Block shared access operations"

Then execute npm run deploy , the deployment is successful

access configuration

After the deployment is successful, enable the static website hosting function

Access the domain name http://robinblog.s3-website-ap-northeast-1.amazonaws.com/ successfully

Summarize

Deployment is really convenient, but the documentation is still not perfect. The documentation mentions the operation of "obtaining credentials", and configuring IAM operation permissions is also a key step, which is mentioned in the documentation, as shown in the following figure:

Spent a lot of time on this.

For more practical procedures, please refer to https://aws.amazon.com/cn/getting-started/?nc2=h_ql_le_gs&trk=4601add5-b05e-40e5-86a4-84b8eec3a582&sc_channel=ba


亚马逊云开发者
2.9k 声望9.6k 粉丝

亚马逊云开发者社区是面向开发者交流与互动的平台。在这里,你可以分享和获取有关云计算、人工智能、IoT、区块链等相关技术和前沿知识,也可以与同行或爱好者们交流探讨,共同成长。