Serverless Framework - AWS CloudFront with S3 origin and multiple behaviours - amazon-cloudfront

I need to configure serverless.yaml as following:
1) 3 environments (stages) - dev ,qa ,prod
2) qa and dev should be ip restricted.
CloudFront serving static html files from S3.
S3 bucket :
qa/index.html
dev/index.html
prod/index.html
1)
The goal is to create a cloudfront distribution that has 3 behaviours that distribute to the corresponding origin (dev,qa,prod)
-another option is to create 3 separate cloudfronts for each stage
2)
In order to ip restrict I understand that WAF is required, and WAF is applied to the CF so, dev and qa can share cloudfront where prod should be in separate.
The question is, does serverless framework has plugins/documentation somewhere that can be helpful in such configuration? Didn't find anything.
Is it possible to have multiple cloudfronts in the serverless.yml based on stage?
Thanks.

I see you want to deploy a "serverless website" for your Static HTML content, powered by AWS's S3, CloudFront, and WAF services. And that you seek to use the Serverless Framework to launch these resources.
However, you make no mention of Lambda.
Serverless Framework's primary use case is to deploy Lambda functions, and resources related to these Lambda functions. This includes the ones you mentioned S3, CF, WAF, etc.
I think you should take a look at Terraform for a configuration management tool. Terraform does not specialize in anything, and it's designed to handle everything.
I understand the confusion. Serverless is a term that covers a few areas of modern cloud computing.

Related

How to Organize Directory Structure for Terraform

As a novice, iam trying to set up some structure for terraform projects. We as a team will be using terraform for building infrastructure for Aws ,azure and containers. I will be building infra for dedicated application teams and also cloud services individually.my challenge is set up a consistent directory structure which can be used to build all types of cloud and also for dedicated application teams. how can i set up a standard directory structure and how can i manage state file for application teams and individually services
THanks for all your knowledge and lessons to me on this
I can see one generic and one specific question here!
Generic Question: how can i set up a standard directory structure (sic)
This purely depends on how your infrastructure is and what cloud services it uses. I would recommend you to start going through this link to get an idea.
Specific Question: how can i manage state file for application teams and individually services (sic)
As you might be aware, your state file has the details about your infrastructure's state in its entirety and must be stored safely. Besides, since multiple teams are going to be using the Terraform code to update the infrastructure, do save the state file in an S3 bucket (or equivalent object storage service in a different cloud) and have it fetched every time someone runs terraform plan or terraform apply. Reference

Terraform Import All Cloud Infrastructure Services to Statefile

I 'm using many services in Alibaba Cloud like Container Service, VPC, RDS, DNS, OSS and many more.
Instead of importing 1 by 1 of Alibaba Cloud Product Services that used that would take a long time for that.
Is there any elegant and fast way to importing all of the cloud infrastructure to a statefile ?
Yes, you can make a resource list and then run terraform but make sure you can have

Why do we say azure functions is a serverless compute service

Please help me understand why we say azure functions is a serverless compute service. It does require cloud to host it and run. Cloud is also a server still why we are saying it is serverless?
Serverless computing does not mean that servers are out of the picture. Servers are very much required, just like they have been for all these years, or else, where will your code run. The reason why the phrase was coined is that as a developer, you do not need to worry about what server your code runs on. In fact, you do not know which server it eventually runs on. Once your code is deployed, Azure assigns the responsibility of executing the code to the next available server. What Azure ensures, and what is ultimately important for you, is that your code will execute whenever required.
Ref: Serverless Computing with Azure Functions
Hope it makes sense :)
To get a better idea this is how we evolved. Cloud providers are making sure we should only worry about the business logic but nothing else.
IaaS (Infrastructure as a service)
You get a running VM somewhere in the data centre but you are required to maintain everything. From Deployment to patching your VMs or anything running on the VM.
PaaS(Platform as a service)
You are not longer required to maintain platForm but you are still responsible to manage your server in terms of load balancing etc.
FaaS(Function as a service)
Servers are abstracted from you . You are only required to maintain your code without worrying about what's under the hood or how to load balance your servers. It's then cloud provider responsibility to package your code and run it for you. But servers are still there.
Going by the official documentation of Azure Serverless computing service, Azure Functions can be defined as;
Azure Functions is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure. Use Azure Functions to run a script or piece of code in response to a variety of events.
Azure Functions is an event driven, compute-on-demand experience that
extends the existing Azure application platform with capabilities to
implement code triggered by events occurring in virtually any Azure or
3rd party service as well as on-premises systems. Azure Functions
allows developers to take action by connecting to data sources or
messaging solutions, thus making it easy to process and react to
events. Azure Functions scale based on demand and you pay only for the
resources you consume.
Here the serverless compute service is like a metaphor which implies, the end user doesn't need to manage the servers or infrastructure to run the applications over the Azure and can spend time to focus on managing and improving the business logic.
Few more points to consider,
Serverless in Azure builds on an open-source foundation, the core of
which is Azure Functions, an event-driven compute experience and open
source project. Community contributions include support for new
languages, integrations and deployment targets.
Azure Functions can be used on-premises, in hybrid environments such as Azure Stack, on IoT Edge devices and deployed on top of orchestrators such as Kubernetes – as well as in other clouds.
They enable faster time to market with lower infrastructure and operating costs.
There are heaps of definition of serverless which you can easily google. But I will share my understanding anyways.
1. It does require cloud to host it and run.
You are correct with this. But anything on Cloud requires Cloud, doesn't it? Azure being one of the cloud providers consists of hundreds of services to cater to different needs people are after from using Cloud.
2. Cloud is also a server still why we are saying is serverless
This is not quite right. Cloud is different from a server. Server is a physical box sitting somewhere. With hundreds of thousands of servers all over the world, Cloud hosts all sorts of different services on these servers.
The reason we say Functions are serverless is that the infrastructure of hosting a Function is abstracted away from devs. It is still deployed to some servers but Azure is responsible for all the resource managing, configuration, load balancing, scaling and networking etc. It allows developers to focus primarily on their code, not having to worry about servers.

How would you compare Hashicorp-Terraform with serverless framework?

I would like to know what is the difference between Terraform and Serverless. Arent they doing the same thing like managing your infrastructure, and representing your infrastructure as code?
Do you really need a serverless framework (serverless.com)?
Thanks
My understanding for serverless framework and other similar serverless-focus tools:
Both Serverless Framework and Terraform support different cloud providers. Use AWS as sample in next statements.
Compare Serverless framework to Terraform, serverless framework is serverless specialist, Terraform is GP
terraform is fully Infrastructure as Code which covered most resources.
Serverless framework is a middle layer only to generate Cloudformation template which mostly for serverless related resources, in aws, focus on lambda, api gateway, dynamodb, etc.
You can write all in Cloudformation template directly, but the template file will be huge, it is hard to maintain by its JSON/Yaml template as well. With a few dozen lines in serverless.yml, serverless framework can generate a thousand or several thousand lines of cloudformation template. It saves a lot of time to deal with the cloudformation coding. By the way, if you already knew cloudformation syntax, you can easily put the same cloudformation yaml codes directly in the resources part, serverless template knows how to create them.
You can write Terraform codes to manage lambda, api gateway, Dynamodb as well. Maybe you can get less codes than Cloudformation template, but still too complicated.
In another way, it doesn't make sense to let serverless framework deal with all AWS resources, that other tools do most well already, such as EC2, VPC, ECS, etc.
Serverless framework is still in developing, because of its popularity, many developers are involved to add features into it daily. Maybe one day you can get what you need, but now you have to mix serverless framework with Cloudformation or Terraform or other tools together in some case.
The most obvious difference is that serveless architecture focuses on function-as-a-service and terraform is designed to manage infrastracture including your EC2 and ECS instances.Serveless.com might be more suited for AWS Lambda deployments (and it's equivalents in other clouds) but it can't manage your virtual machines, load balancers and all the other.
I find that Serverless just handles the configuration of Lambda and API Gateway better. The deployment is less of a hassle as well.
In fact, I have a few projects where Serverless handles Lambda functions + endopints, and any other resource is handled by Terraform.
You could even use Terraform to deploy Serverless projects using local-exec commands.
2021 update: the Serverless team explained the difference themselves in this blog post.
The gist of it is that the two can be used together:
Serverless is more suitable to manage application specific infrastructure that gets torn down and re-created at every deploy
Terraform is more suitable to handle shared, more stateful infrastructure
From the blog post:
For example
If you have a shared database and two Serverless applications that create tables in it, the database should be managed by Terraform. The specific tables should be created and destroyed by the Serverless Framework during the app deployment and teardown process.

Is there any alternative for WebJobs in AWS (like in Azure)?

I need to implement scheduled tasks, so that every X time the job will start running and will start an .exe file.
I did this those tasks in Azure very easily, but can't find something appropriate in Amazon Web Services.
Can you tell me if there is something similar in AWS for Azure WebJobs?
The most similar piece of AWS services that fits your needs is AWS Lambda. But as your comment states you do not want to code.
When comparing AWS to other cloud services it pops out that AWS focus on a very primitive services that can be connect and build complex systems. This is an advantage as one can tailor the cloud to its needs. However it can be more complex to setup when compared to a PaaS.

Resources