小泉  亮介

小泉 亮介

1598110140

AWS CLIを使って、Amazon S3で静的ウェブサイトをホスティングしたい

みなさん、どうもたいがーです

入社してもうすぐ丸二か月が経つそうです。時間が経つのは早いですね。

AWS CLIを使うのが楽しくなってきた、今日この頃。

今やっていることも、CLIを使ってできないのかな・・・なんて考えています。

そんな今回は、AWS CLIを使ってAmazon S3を操作し、静的ウェブサイトのホスティングをやっていきたいと思います。

実行環境

  • AWS CLI v2.0.14

やってみよう

手順をざっくりまとめると、このような感じです。

  1. 公開用のS3バケットを作成。そのバケットのアクセスブロックを確認し、設定する
  2. バケットポリシーを作成、S3バケットにアタッチする
  3. テストページ用のhtmlファイルを作成し、S3バケットにアップロードする
  4. S3バケットにウェブサイトの設定を行う

公開用のS3バケットを作成。そのバケットのアクセスブロックを確認し、設定する

  • 公開用にS3バケットを作成します。バケットの命名規約等はこちらをご覧ください。
aws s3 mb s3://[backet-name]

  • _for-test-page_バケットのアクセスブロックを設定し、公開できる状態にします。
aws s3api put-public-access-block --bucket [backet-name] --public-access-block-configuration  "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"

  • きちんと反映できているか、確認してみましょう。
aws s3api get-public-access-block --bucket [backet-name]

{
    "PublicAccessBlockConfiguration": {
        "BlockPublicAcls": false,
        "IgnorePublicAcls": false,
        "BlockPublicPolicy": false,
        "RestrictPublicBuckets": false
    }
}

#初心者向け #その他 #aws cli #amazon s3

What is GEEK

Buddha Community

AWS CLIを使って、Amazon S3で静的ウェブサイトをホスティングしたい

How to Upload to Amazon S3 via AWS CLI and NPM scripts

Static websites are a brilliant way to create performant sites. My website is built using Gatsby and hosted on Amazon S3. I have created a simple script to help you quickly upload your site to S3 by running one simple command in your project terminal.

Prerequisites

Before we start, you must ensure that you have completed the following:

  • Install AWS CLI (Amazon Web Services Command Line Interface) on your machine.
  • Create a bucket in Amazon S3 (this is where we will be uploading our project files to).

This guide assumes that you have some familiarity navigating the AWS Console and each Amazon Web Service.

#aws-s3 #npm #amazon-web-services #amazon #aws #cloud #aws-services

Seamus  Quitzon

Seamus Quitzon

1601341562

AWS Cost Allocation Tags and Cost Reduction

Bob had just arrived in the office for his first day of work as the newly hired chief technical officer when he was called into a conference room by the president, Martha, who immediately introduced him to the head of accounting, Amanda. They exchanged pleasantries, and then Martha got right down to business:

“Bob, we have several teams here developing software applications on Amazon and our bill is very high. We think it’s unnecessarily high, and we’d like you to look into it and bring it under control.”

Martha placed a screenshot of the Amazon Web Services (AWS) billing report on the table and pointed to it.

“This is a problem for us: We don’t know what we’re spending this money on, and we need to see more detail.”

Amanda chimed in, “Bob, look, we have financial dimensions that we use for reporting purposes, and I can provide you with some guidance regarding some information we’d really like to see such that the reports that are ultimately produced mirror these dimensions — if you can do this, it would really help us internally.”

“Bob, we can’t stress how important this is right now. These projects are becoming very expensive for our business,” Martha reiterated.

“How many projects do we have?” Bob inquired.

“We have four projects in total: two in the aviation division and two in the energy division. If it matters, the aviation division has 75 developers and the energy division has 25 developers,” the CEO responded.

Bob understood the problem and responded, “I’ll see what I can do and have some ideas. I might not be able to give you retrospective insight, but going forward, we should be able to get a better idea of what’s going on and start to bring the cost down.”

The meeting ended with Bob heading to find his desk. Cost allocation tags should help us, he thought to himself as he looked for someone who might know where his office is.

#aws #aws cloud #node js #cost optimization #aws cli #well architected framework #aws cost report #cost control #aws cost #aws tags

Hire AWS Developer

Looking to Hire Professional AWS Developers?

The technology inventions have demanded all businesses to use and manage cloud-based computing services and Amazon is dominating the cloud computing services provider in the world.

Hire AWS Developer from HourlyDeveloper.io & Get the best amazon web services development. Take your business to excellence with our best AWS developer that will serve you the benefit of different cloud computing tools.

Consult with experts: https://bit.ly/2CWJgHyAWS Development services

#hire aws developer #aws developers #aws development company #aws development services #aws development #aws

Lindsey  Koepp

Lindsey Koepp

1603458624

A Beginner's Guide to Amazon EC2 (Elastic Compute Cloud)

Amazon EC2 is a service that allows you businesses to run their application in AWS cloud. You can easily set up a virtual machine and perform all your computation on it. In this post, we will teach you the basics of Amazon EC2.

Introduction

EC2 is one of the oldest and fundamental services of AWS. Though everything today is serverless, you still need to know EC2. EC2 allows you to do the following things :

  • Rent virtual machines (EC2 itself)
  • Store data on virtual drives (EBS)
  • Distribute load across the machines (ELB)
  • Scale the services using an auto-scaling group (ASG)

Amazon Machine Image – AMI

AMIs are the templates from which virtual servers (EC2 instance) get created.

In simple terms, AMIs are the collection of the operating system, architecture (32-bit or 64-bit) with the softwares that will be running on that operating system.

For example:

  • Amazon Linux AMI is the one that comes with a Linux operating system and many packages of the Linux that one might need.

  • Windows AMI comes with Windows as its operating system and software one might need.

By choosing AMI you basically decide the software part of your EC2 machine. You can use a single AMI and launch multiple instances from it.

#aws #aws-cloud #aws-iam #aws-certification #aws-top-story #ec2 #virtual-machine #amazon-web-services

Christa  Stehr

Christa Stehr

1598408880

How To Unite AWS KMS with Serverless Application Model (SAM)

The Basics

AWS KMS is a Key Management Service that let you create Cryptographic keys that you can use to encrypt and decrypt data and also other keys. You can read more about it here.

Important points about Keys

Please note that the customer master keys(CMK) generated can only be used to encrypt small amount of data like passwords, RSA key. You can use AWS KMS CMKs to generate, encrypt, and decrypt data keys. However, AWS KMS does not store, manage, or track your data keys, or perform cryptographic operations with data keys.

You must use and manage data keys outside of AWS KMS. KMS API uses AWS KMS CMK in the encryption operations and they cannot accept more than 4 KB (4096 bytes) of data. To encrypt application data, use the server-side encryption features of an AWS service, or a client-side encryption library, such as the AWS Encryption SDK or the Amazon S3 encryption client.

Scenario

We want to create signup and login forms for a website.

Passwords should be encrypted and stored in DynamoDB database.

What do we need?

  1. KMS key to encrypt and decrypt data
  2. DynamoDB table to store password.
  3. Lambda functions & APIs to process Login and Sign up forms.
  4. Sign up/ Login forms in HTML.

Lets Implement it as Serverless Application Model (SAM)!

Lets first create the Key that we will use to encrypt and decrypt password.

KmsKey:
    Type: AWS::KMS::Key
    Properties: 
      Description: CMK for encrypting and decrypting
      KeyPolicy:
        Version: '2012-10-17'
        Id: key-default-1
        Statement:
        - Sid: Enable IAM User Permissions
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
          Action: kms:*
          Resource: '*'
        - Sid: Allow administration of the key
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:user/${KeyAdmin}
          Action:
          - kms:Create*
          - kms:Describe*
          - kms:Enable*
          - kms:List*
          - kms:Put*
          - kms:Update*
          - kms:Revoke*
          - kms:Disable*
          - kms:Get*
          - kms:Delete*
          - kms:ScheduleKeyDeletion
          - kms:CancelKeyDeletion
          Resource: '*'
        - Sid: Allow use of the key
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:user/${KeyUser}
          Action:
          - kms:DescribeKey
          - kms:Encrypt
          - kms:Decrypt
          - kms:ReEncrypt*
          - kms:GenerateDataKey
          - kms:GenerateDataKeyWithoutPlaintext
          Resource: '*'

The important thing in above snippet is the KeyPolicy. KMS requires a Key Administrator and Key User. As a best practice your Key Administrator and Key User should be 2 separate user in your Organisation. We are allowing all permissions to the root users.

So if your key Administrator leaves the organisation, the root user will be able to delete this key. As you can see **KeyAdmin **can manage the key but not use it and KeyUser can only use the key. ${KeyAdmin} and **${KeyUser} **are parameters in the SAM template.

You would be asked to provide values for these parameters during SAM Deploy.

#aws #serverless #aws-sam #aws-key-management-service #aws-certification #aws-api-gateway #tutorial-for-beginners #aws-blogs