Hands-On Serverless Applications with Kotlin
Hardik Trivedi Ameya Kulkarni更新时间:2021-07-23 19:09:53
最新章节:Leave a review - let other readers know what you think封面
Title Page
Copyright and Credits
Hands-On Serverless Applications with Kotlin
Packt Upsell
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewer
Packt is searching for authors like you
Preface
Introduction
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Basics of Serverless
What is serverless computing?
The evolution of serverless computing
On-premise
Colocation providers
Virtualization and IaaS
PaaS
BaaS
SaaS
FaaS
Serverless computing
Serverless – the time is now
Diving into serverless computing with a use case
A review of serverless computing
Comparing and contrasting traditional and serverless paradigms
The case study of an application
The architecture of the system using traditional methods
The architecture of the system using the serverless paradigm
Traditional versus serverless in a nutshell
Pros and cons of serverless
Advantages of serverless systems
Reduced operational costs
Optimized resource utilization
Faster time to market
High-development velocity and laser-sharp focus on authoring code
Promoting a microservices architecture
The drawbacks of serverless systems
Nascent ecosystem
Yielding of control
Opinionated offerings
Provider limits
Standardized and provider-agnostic offerings
Tooling
Competition from containers
Rethinking serverless
An absence of local states
Applying modern software development practices
Time-boxed execution
Startup latency
Testability
Debugging
The serverless computing ecosystem
Serverless computers and infrastructure providers
AWS Lambda
IBM OpenWhisk
Microsoft Azure Cloud Functions
Google Cloud Functions
Auth0 Webtasks
Others
Serverless toolkits
Summary
AWS Serverless Offerings
AWS Lambda overview
Execution environment
Service limits
Invocation types
Custom invocation via AWS CLI or embedded AWS SDK in an application
Event sources from other AWS Services
Execution environments/runtimes
Handler
Context
Logging
Exceptions and error handling
Storing the state
JVM execution environment
Handlers in Java
Context object
Logging
Error handling
A case study of a simple Java Lambda function
Creating the Lambda function
Lambda dashboard
Basics of creation
Configuring the Lambda function
Writing a Lambda function
Deploying the Lambda function
Testing a Lambda function
Case study of a simple Kotlin Lambda function
Tooling
Anatomy of a Kotlin Lambda function
Project structure
build.gradle
Handler
Packaging and deploying
Testing the Kotlin function
Integrating a Lambda function with an upstream component
Types API Gateway and Lambda integrations
Lambda integration/ Lambda custom integration
Lambda proxy integration
Anatomy of the Lambda function when used in Lambda proxy integration
Creating an API Gateway
Integration testing
Deploying the API Gateway
End-to-end test
Basic monitoring of lambda functions
Versioning Lambda functions
Summary
Designing a Kotlin Serverless Application
The problem statement
Analyzing the problem statement
Functional specifications of the app
Designing the serverless API
Architectural and design decisions
AWS Cognito for login and registration
The Kotlin language
PostgresSQL 10 on Amazon RDS
API Gateway for proxy and edge engineering
API keys and usage plans
Authorization
Defining request and response models
API Gateway extensions to Swagger
Swagger 2.0 JSON documentation with API Gateway extensions
AWS Lambda as an FaaS platform
System design
Domain models
APIErrorResponseWithMessage
APISuccessResponseWithMessage
Poll
PollCreationRequest
RespondentDetails
PollResponseStatistics
PollDetails
API model
Registering a respondent
Fetching all Polls
Creating a Poll
Fetching a Poll
Deleting a Poll
Responding to a Poll
Persistence layer design
Connecting to the instance
Configuring an application user
Schema definition
Security and access control to the API
API key
Cognito authorizer for API
Note on the local development environment
Setting up
AWS Account
Installing IntellIj Idea CE
PostgreSQL
Third-party libraries
Liquibase
JOOQ
Build life cycle
Summary
Developing Your Serverless Application
Preparing the serverless environment
Configuring a Cognito pool
Swagger for the API
Implementing lambda functions
Writing your first lambda function in Kotlin
Choosing an IDE
Setting up a project
Writing a function that returns dummy static data
Data classes
Default parameters
Mutable list
Converting JSON into models using Jackson
The apply() function
Building a fat JAR
Deploying a JAR
Testing and executing
Implementing other lambda functions in Kotlin
Preparing the data classes
Registering respondents
Creating a poll
Getting a poll
Kotlin and the builder pattern
Implementation of the app
Setting up AWS Authentication using Cognito pool
Connecting to your backend
Object declaration
Integrating the API
Configuring the API client
Singleton
Lateinit versus lazy initialization
Lateinit
The lazy property
Interfaces
Rxify the API call
Lambda functions
Some interesting implementations
Returning data from a function
The destructuring declaration
Kotlin's approach to anonymous classes
Summary
Improving Your App with Firebase Service
About Firebase
Firebase authentication
Configuring authentication methods
Configuring the client app to use the authentication service
The when() expression
Improving the signIn() function using Lambda functions
Extension functions
Ditching the findViewById() method
View extensions
Firebase cloud functions
Prerequisites
Setting up the project
Creating a simple cloud function
Deploying the cloud function
Saving data into the real-time database
Structuring the request model
Structuring and saving the database object
Getting the list of polls
Interoperability with JavaScript
Monitoring crashes
Customizing the crash reports
Adding custom logs and keys
Monitoring the application's performance
How does it work?
Monitoring HTTP/s network requests
Using the SDK
Summary
Analyzing Your Application
What are non-functional requirements?
AWS CloudTrail
AWS CloudWatch
AWS CloudTrail
Concepts
Overview
Event packet structure
Integrations
AWS services supported for CloudTrail auditing
AWS services not supported for CloudTrail auditing
Example
Creating a simple audit trail for auditing Lambda configurations
Creating a trail
Advanced configuration of the trail
The created trail
Trail repository
AWS CloudWatch
Concepts
Metrics
Namespaces
Logs
Alarms
Dashboards
A practical walk-through
Visualization using CloudWatch dashboards
Creating a dashboard for Greeter metrics
Creating a dashboard
Adding widgets
Metrics selection for Lambda
Creating a widget for the API Gateway metrics
Dashboard preview
Test run
Integration of CloudTrail and CloudWatch
Configuring CloudWatch with CloudTrail
Creating an IAM role
Verifying the integration
Summary
Secure Your Application
AWS security concepts
Account access
Root credentials
Enabling Multifactor authentication
Need based account creation
IAM groups
Password policy
IAM roles and policies
Subject/principal
Resources
Permissions
Policies
Groups
Roles
Identities
Users
Best practices for creating IAM users
Creating individual users
The principle of least privilege
Leveraging predefined policies
Rotating passwords and keys
Using temporary credentials
IAM policy conditions
Continuous and exhaustive monitoring
AWS Virtual Private Cloud
Subnets
Private subnets
Public subnets
Security groups
Inbound
Outbound
Infrastructure hardening
Hardening AWS Cognito
Security measures for users
Allowing user signup
Expiring unused accounts
Setting password policies
Enabling MFA
User verification
Hardening AWS API Gateway
SSL/HTTPS
API key and usage plans
Resource policies
Authorizers
CORS support
Throttling
Hardening AWS Lambda
Using KMS to encrypt sensitive information
Execution role
Hardening AWS RDS
Moving RDS into a VPC's private subnet
Do not use master credentials
Practical walk–through
Setting up the test bed
Database access using JOOQ
The build.gradle file
Handler
Invocation
Database configuration as environment variables
Defining environment variables
Modifying the handler to source these environment variables
Building and deploying
Invoking the API
Encrypting the environment variables
Configuring KMS
Creating a Key
Supplying key details
Defining administrative permissions
Defining usage permissions
Key created
Configuring Lambda with KMS
Enabling encryption in transit
Decrypting in the handler
Boilerplate decryption
The handler class
The build.gradle file
Deploying and testing
Creating an RDS user
Creating a user
Granting privileges
VPC changes
Current setup
Creating the VPC
Creating security groups
Security groups for Lambda
Security groups for RDS
Modification of RDS
Modification of Lambda
Attaching security groups and specifying subnets
Modifying permissions of the IAM role
Conclusion of the walk–through
Summary
Scale Your Application
Infrastructure as code
Serverless Framework
Concepts
Providers
Services
Resources
Functions
Events
Practical walk-through
Getting started
Installation
Prerequisites for installation
Installing the framework
Configuring the CLI tool
Bootstrapping the project
Creating a service
Code organization and boilerplate
Workspace structure
The build.gradle file
The serverless.yaml file
Workflow
Building the package
Deploying the entire Service
Deploying a single function
Actual workflow
Environment variables
Provisioning the VPC
Creating a VPC
Creating and attaching the internet gateway
Public subnet
Private subnet
NAT gateway
Elastic IP allocation
Creation of NAT gateway and EIP Association
Route association
Creating a Route Table for the Public Subnet
Default Public Route
Association of a Public Route Table to a Public Subnet
Routing in the Private Subnet
Security groups
Provisioning IAM policies and roles for Lambda execution
Execution role creation
Basic execution policy
VPC execution policy
Provisioning a Cognito user pool
Provisioning the KMS key
Provisioning RDS
Provisioning lambda functions
Model definitions
API gateway Validation
Installing the request validator plugin
Usage of the plugin
Integration of the validators
Lambda to Register a Respondent
Lambda to fetch all polls
Lambda to create polls
Lambda to delete a poll
Lambda to fetch a poll
Lambda for responding to a poll
Lambda to migrate the database
Lambda to fix the database migrations
Caveats while scaling Serverless applications
Lambda execution life cycle
Workarounds for scaling lambda functions
Summary
Advanced AWS Services
AWS Cloud9
Introduction to Cloud9
How does it work?
Getting started
Prerequisites
Setting up an EC2 environment
Best practices
Usage patterns
Supported languages
Practical walk-through of authoring the lambda function in Cloud9
Use cases of Cloud9
AWS Alexa
Introduction to Alexa
Building blocks
Skills
Skills Kit
Interaction model
Invocations
Intents
Slot types
Interfaces
Functional endpoints
Account linking
Walkthrough of creating a simple custom Alexa Skill
Problem statement
Creating a skill
Registration on Amazon Developer Console
Naming a skill
Defining invocations
Defining intents and utterances
Linking the functional endpoint
Creating a Lambda function
A few tweaks
The build.gradle file
Entrypoint handler function
Technical architecture handler
The serverless.yaml file
Building the lambda function
Deploying the lambda function
Linking the Lambda to the Skill
Testing
Applying the finishing touches
Distribution and certification
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
更新时间:2021-07-23 19:09:53