Perspektywa... ma znaczenie :)





Wild static website on AWS appeared! Static website on AWS used CONFUSION!
Static website on AWS used CONFUSION! Critical hit!

aws-in-plain-english


                        {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Sid": "PublicReadGetObject",
                                    "Effect": "Allow",
                                    "Principal": "*",
                                    "Action": "s3:GetObject",
                                    "Resource": "arn:aws:s3:::example.com/*"
                                }
                            ]
                        }
                    
...

mat3e used AWS S3!

It's super effective!

Static website on AWS used 70MB! It's not very effective...

$$$

S3 Standard Storage
First 50 TB / Month $0.023 per GB
Next 450 TB / Month $0.022 per GB
Over 500 TB / Month $0.021 per GB
Data Transfer IN/OUT S3-Internet
All data transfer in $0 per GB
Out up to 1 GB / Month $0 per GB
Out, next 9.999 TB / Month $0.09 per GB
Request pricing
Data Returned by S3 Select $0.0007 per GB
Data Scanned by S3 Select $0.002 per GB
PUT, COPY, POST, or LIST Requests $0.005 per 1,000 requests
GET, SELECT and all other Requests $0.0004 per 1,000 requests

Prawo Chrzonstowskiego

Wraz z rozwojem firmy, jej zapotrzebowanie na chmurę publiczną rośnie, maleje, rośnie, maleje, ... (hipoteza) aż do utworzenia przez nią nowej chmury publicznej

...

Static website on AWS used ugly URL! Critical hit!

http://example.com.s3-website-eu-west-1.amazonaws.com

  • DNS ALIAS?
    (brak stałego adresu IP)
  • CNAME?

Dystrybucja!

Domena w AWS

Certyfikat
AWS Certificate Manager

...

mat3e used Route 53, ACM, CloudFront combo! It's super effective!

Static website on AWS fainted!

wiele expa

$$$

CloudFront różnie, np. odbiór 1 GB (aż do 10 TB)
  • $0.114 w Japonii
  • $0.085 w krajach Europy


+ 0,50 $ + VAT za Route 53!
...

What? Static website on AWS is evolving! Into Website with visitor counter!
...

Website with visitor counter used new requirements! Critical hit!

Baza!

Lambda!


                        const AWS = require('aws-sdk');
                        const doc = require('dynamodb-doc');
                        AWS.config.update({ region: 'eu-west-1' });
                        const dynamo = new doc.DynamoDB();
                        
                        const TableName = 'table';
                        const Key = { id: 1 };
                        
                        exports.bumpCounter = async(event, context) => {
                            const result = await dynamo.getItem({ TableName, Key }).promise();
                            return {
                                statusCode: 200,
                                body: JSON.stringify(result) // { Item: { /* keys and values */ } }
                            };
                        };
                    

Uprawnienia

Wystawienie tego na świat


                        const { counter } = await dynamo.getItem({ TableName, Key }).promise();
                        return {
                            statusCode: 200,
                            body: JSON.stringify(
                                (await dynamo.updateItem({
                                    TableName,
                                    Key,
                                    UpdateExpression: `set counter = ${counter + 1}`,
                                    ReturnValues: 'UPDATED_NEW'
                                }).promise()).Attributes
                            )
                        };
                    
...

mat3e used DynamoDB, Lambda, IAM & Gateway! It's super effective!

Website with visitor counter used errors! Critical hit!

Monitoring!

Logi, metryki, spięcie się z console.log :)
Invalid UpdateExpression
The provided expression refers to an attribute that does not exist in the item
const { counter } = await dynamo.getItem({ TableName, Key }).promise();const { Item: { counter } } = await dynamo.getItem({ TableName, Key }).promise();
                            return {
                                statusCode: 200,
                                body: JSON.stringify(
                                    (await dynamo.updateItem({
                                        TableName,
                                        Key,
                                    UpdateExpression: `set counter = ${counter + 1}`,            UpdateExpression: 'set #C = :counter',
            ExpressionAttributeNames: { '#C': 'counter' },
            ExpressionAttributeValues: { ':counter': (counter + 1) },
                                        ReturnValues: 'UPDATED_NEW'
                                    }).promise()).Attributes
                                )
                            };
                        
...

mat3e used CloudWatch!

It's super effective!

Website with visitor counter used CORS! Critical hit!

...

mat3e used Gateway & Lambda settings! Critical hit!

Website with visitor counter fainted!

wincyj expa

$$$

  • Milion wywołań Lambdy w miesiącu = 0,00 $!
  • 25 GB w DynamoDB = 0,00 $! Read/write? Pomijalne dla 70 MB
  • API Gateway = 3,5 $ za milion żądań
  • IAM = 0,00 $!
  • 0,30 $ za metrykę (do 10k metryk)
  • 0,57 $ za GB logów
  • 3 $ za dashboard

Na koniec

  • Stronka z licznikiem odwiedzin = 9 usług AWS
    • S3, CloudFront, Route 53, Certificate Manager
    • Licznik: DynamoDB, Lambda, API Gateway, CloudWatch, IAM
  • Warto zrobić nawet sam licznik, dla sportu :)
  • Dalszy rozwój?
    • Monitoring kosztów (Billing), podpięcie SNS