# Developing AWS (Advanced) ## Sharding: Sharding write-heavy partition keys. Distribute work loads evenly across partition keys. Hotkey - One partition gets too many reads Hot partiition- one partion receiv higher volume of read-write ## Day 5 Data Velocity & Volume : Kinesis Example: Sensor Networks Click Streams Log Shipping Centralizatin Real-time processing Kinesis stores data up to 24 hours. Bottleneck => More shards Split or Merge Shards as needed. Producers: SQS PUT to Kinesis Stream Consumer KCL - Kinesis Client Library ![](https://i.imgur.com/XdTuoes.png) Links from Jesse https://hackmd.io/TnYNDFVTT1Ohfb5qrmAU6g https://hackmd.io/gv-wMHFgTT63g_sgUK1hfg **CAP Theorem** Consistancy Availability Partition Tolerence SPoF --- AppSync : fully managed GraphQL ---- # Lab 5 Developing microservices on AWS Build and Run Unit test on the code locally Generate deployment artifacts and Copy the artifacts to S3 bucket `aws s3 cp target/tripsearch-1.0.0.jar s3://qls-4160611-bb58f5f7e7f5a9e5-s3bucketlambdacode-y95i7s8z1cl9 --region us-west-2 --profile aws-lab-env` Create lambda function using the deployment artifact. ``` aws lambda create-function --function-name microservicesTripSearchFull --runtime java8 --role arn:aws:iam::628405585836:role/microservicesLambdaExecutionRole --handler microservices.lambda.FindAllTripsHandler --code S3Bucket=qls-4160611-bb58f5f7e7f5a9e5-s3bucketlambdacode-y95i7s8z1cl9,S3Key=tripsearch-1.0.0.jar --timeout 15 --description "CloudAir TripSearch microservice - FindAllTrips" --memory-size 1024 --profile aws-lab-env ``` An output similar to the following will be visible: ``` { "LastUpdateStatus": "Successful", "FunctionName": "microservicesTripSearchFull", "LastModified": "2021-04-24T16:52:37.328+0000", "RevisionId": "95f61dda-0a15-4442-8cc5-a57e625a057b", "MemorySize": 1024, "State": "Active", "Version": "$LATEST", "Role": "arn:aws:iam::628405585836:role/microservicesLambdaExecutionRole", "Timeout": 15, "Handler": "microservices.lambda.FindAllTripsHandler", "Runtime": "java8", "TracingConfig": { "Mode": "PassThrough" }, "CodeSha256": "YPUxKNfDAZRxNb8pj9L9YOJuGKKZrB/AwmWKTXLm8uc=", "Description": "CloudAir TripSearch microservice - FindAllTrips", "CodeSize": 9737281, "FunctionArn": "arn:aws:lambda:us-west-2:628405585836:function:microservicesTripSearchFull", "PackageType": "Zip" } ``` if the deployment artifact contains multiple handlers, a separate lambda funtion can be created for each handler. (Just chnage the handler name in the command as shown below ): ``` aws lambda create-function --function-name microservicesTripSearchFromCity --runtime java8 --role arn:aws:iam::628405585836:role/microservicesLambdaExecutionRole --handler microservices.lambda.FindTripsFromCityHandler --code S3Bucket=qls-4160611-bb58f5f7e7f5a9e5-s3bucketlambdacode-y95i7s8z1cl9,S3Key=tripsearch-1.0.0.jar --timeout 15 --description "CloudAir TripSearch microservice - FindTripsFromCity" --memory-size 1024 --profile aws-lab-env aws lambda create-function --function-name microservicesTripSearchToCity --runtime java8 --role arn:aws:iam::628405585836:role/microservicesLambdaExecutionRole --handler microservices.lambda.FindTripsToCityHandler --code S3Bucket=qls-4160611-bb58f5f7e7f5a9e5-s3bucketlambdacode-y95i7s8z1cl9,S3Key=tripsearch-1.0.0.jar --timeout 15 --description "CloudAir TripSearch microservice - FindTripsToCity" --memory-size 1024 --profile aws-lab-env ``` Go to Api Gateway and create a new REST api Enter API name, path and enable CORS Create Resource --> Resource wil be created from actions, choose create method, select GET and continue Integrate with the Lambda function Click Save and Test. We will see something like this; ![](https://i.imgur.com/fPQH5HG.png) In the integration request, create mapping template and add mapping template. Test the API aws cloudformation package --template template.yml --s3-bucket qls-4160611-bb58f5f7e7f5a9e5-s3bucketlambdacode-y95i7s8z1cl9 --output-template template-export.yml --profile aws-lab-env http://qls-4160611-bb58f5f7e7f5a9e5-s3bucketwebsite-hz2ayjsge4m.s3-website-us-west-2.amazonaws.com aws s3 sync . s3://qls-4160611-bb58f5f7e7f5a9e5-s3bucketwebsite-hz2ayjsge4m --profile aws-lab-env