Monday, January 14, 2019

AWS Developer Associate - 2

S3 - Simple Storage Service

  1. for files/images/web pages
  2. Fundamentals
    1. Key
    2. Value
    3. Version
    4. Metadata
    5. Subresources - bucket specific configuration
      1. Policies, ACL
      2. CORS - Cross Origin Resource Sharing
      3. Transfer Acceleration
  3. object based, not block storage
  4. HA, DR
  5. file size: 0bytes to 5 TB
  6. Unlimited Storage
  7. HTTP 200 on successful upload
  8. Data Consistency
    1. Read after Write for PUTS of new objects
    2. Eventual consistency for overwrite PUTS
  9. Amazon guarantees 99.9% availability
  10. Amazon guarantees 99.(11 9s) % durability
  11. Tiers/Classes
    1. Regular - can sustain the loss of 2 facilities concurrently
    2. Infrequent Access - low fee, but charged for retrieval
    3. OneZone - 99.5% availability, 20% less cost than regular
    4. Reduced Redundancy Storage: 99.99% durability, ex for thumbnails, may be deprecated
    5. Glacier: Cheap, optimized for infrequent access, takes 3-5 hours to restore data, archives
    6. Intelligent Tiering - unknown access patterns, data not accessed for 30+ days, moved to infrequent, after access, moved to frequent tier, optimized cost
      1. Frequent
      2. Infrequent
  12. Charged for:
    1. Storage/GB
    2. Requests
    3. Storage mgmt - inventory/analytics/tags
    4. Data mgmt - data taken out of S3
    5. Transfer acceleration


AWS Developer Associate - 1

Amazon does not launch new services in all regions.
Normally services are first launched in US-East i.e. North Virginia region

Identity and Access Management

In here you get a custom link for your login(contains random numbers), which you can customize to any unused word you want.

Minimum security that AWS recommends:
  1. Delete root access keys
  2. Enable MFA
  3. Create IAM users
    1. Root account should not be used for anything
    2. Restrict access to users and give them access to what they need
  4. Use Groups to assign permissions
    1. We can also give permissions directly to users
  5. Apply password policy


User creation:
You get username and password for console login and access key and secret access  key for API


EC2

Elastic compute cloud
Provides resizable compute capacity
Payment:
  1.  On Demand - fixed rate by hour (linux by second) - no commitment, no upfront payment, good for learning
  2.  Reserved - commitment for 1 or 3 year, discounted hourly rate, 
    1. Standard RI: cost can be 75% off on demand
    2. Convertible RI: 
    3. Scheduled RI:
  3. Spot - allows you to bid, good for flexible timings, price goes above bid, AWS will terminate and not charge, if you terminate, will be charged
  4. Dedicted hosts - usefull if you have server bound software licenses, regulatory requirement for no multi-tenancy


EC2 Instance types:
FIGHTDRMCPX

EBS

virtual disk
elastic block storage - attach to EC2
is replicated

EBS Types:

General purpose SSD: 10K IOPS burst upto 30K IOPS
Provisioned IOPS SSD: DB, extreme performance, >10K IOPS

Throughput optimized HDD (ST1) : no root volumne, data warehouseing, log processing
Cold HDD (SC1): file server, lowest cost, bootable

To connect to EC2, we use SSH for linux and RDP for windows

Load Balancers: Application(layer 7)/Network(most expensive/perf)/Classic(layer 7 or 4)

504 error is gateway timeout, app did not respond

Use header X-Forwarded-For to find out who the load balancer forwarded ipv4

Route53: DNS service

AWS CLI

aws configure
aws s3 ls
aws s3 mb s3://bucket
aws s3 cp hello.txt s3://bucket

User with CLI access might not need console access, dont give it
Always create groups
Secret access key will be shown only once

Dont use access key, use roles instead

RDS

ElastiCache : in-memory cache, faster than DB
Supported engines:

  1. Memcached
  2. Redis
Backup
  1. Automated
    1-35 days recovery, stored on S3, free
  2. Snapshot
    manually, stored after RDS is deleted
Restoring - is a new RDS instance

Multi AZ - disaster recovery, sync
Read replicas - improve performance, async replication, scaling








Sunday, February 21, 2016

for loop in Scala


In Scala, the for is actually foreach, you write it as follows:

val filesHere = (new java.io.File(".")).listFiles
for (file < - filesHere)
println(file)

for (i < - 1 to 4) //gives 1,2,3,4
for (i < - 1 until 4) //gives 1,2,3

We can not only iterate over a sequence but also filter it as follows:

for (
file < - fileshere
if file.isFile;
if file.getName.endsWith(".scala")
) println(file)

Nested loop:

for (
file < - fileshere
if file.getName.endsWith(".scala");
line < - fileLines(file)
if line.trim.matches(pattern)
) println(file +": "+ line.trim)

Creating new collection:

def scalaFiles =
for {
file < - fileshere>
if file.getName.endsWith(".scala")
} yield file

Immutable objects



Positives:
  1. State does not change overtime
  2. Can pass them around freely
  3. Threads don't share an object 
  4. Can identify an object by its hash
Negatives:
  1. Large objects result in performance hit when they are duplicated

Tuesday, December 01, 2015

Currying

After a lot of research I kinda have a sense of why we need currying in functional languages - it turns out, there are some (don't know which) analytical techniques which can only be applied to functions with single argument.

So if we want to use these (mysterious) techniques, we need currying :)

Oh, and of course it gives us a different style of reuse



Sunday, November 15, 2015

while ((line = readLine()) != "") doesn't work in Scala

In C++ or Java, line = readLine() would return the line itself, however, in Scala, assignment to var type variable returns () i.e. Unit, so it cannot be compared to "" in a while loop.

Pure functional languages do not have loops because of this same reason, it does not return anything

Friday, November 13, 2015

Scala Class and Object

class checksumAccumulator {

private var sum = 0

def add(b: Byte): Unit = {
sum += b
}

def checksum(): Int = {
~(sum & 0xFF) + 1
}

}


By default sum is public, we have to explicitly make it private.
Parameter b is by default val, so we cannot re-initialize it in checksum method, there is no return keyword, in such case, last value computed by method is returned - this is the recommended style - avoid explicit and multiple return statements

class ChecksumAccumulator {
private var sum = 0
def add(b: Byte) { sum += b }
def checksum(): Int = ~(sum & 0xFF) + 1
}

since our methods are just single statements, they can be written without {}, also when method does not return anything, i.e. its return type is Unit, we can skip writing the return type and "=", like in the add method

all datatypes can get converted to Unit - it simply looses the data
semicolon at the end of the statement are optional

object ChecksumAccumulator {
}

defining object instead of class gives singleton of the class called companion object class
A class and its companion object can access each other’s private members.

To run a Scala program, you must supply the name of a standalone singleton object with a main method that takes one parameter, an Array[String], and has a result type of Unit. Any singleton object with a main method of the proper signature can be used as the entry point into an application.

object Summer {
def main(args: Array[String]) {
}
}

We can also write the following:

object FallWinterSpringSummer extends Application {
}