Daisy Rees

Daisy Rees

1566374725

Deploying a Node 12 Function to Cloud Run

Originally published by Grant Timmerman at https://medium.com

Let’s say this.

  • You learn that the Node Foundation releases cutting-edge
  • Node 12
  • .It includes cool new features like more performant async/await, faster HTTP parsing, and private fields. It’s still in development but you want to use it for your services.But Google Cloud Functions doesn’t support Node 12 yet.

So whatchagunnado?

  • Blog about it?

…Maybe

  • Or use Cloud Run

Let’s learn how to do that!

Deploying a Node 12 Function to Cloud Run

Node is a JavaScript runtime built on Chrome’s V8 engine.

Cloud Run (http://cloud.run) is a managed, serverless computing platform that abstracts away infrastructure management, so you can focus on building great applications.

Together, you can build scalable services atop Google Cloud in minutes.

First, Install Node 12

TJ has an incredibly simple Node module called n for managing Node versions (i.e. switching between 10 and 12). Install the global CLI called n:

sudo npm i n -g

Then switch your Node version to Node 12:

sudo n 12

Verify your Node version

node -v # v12.7.0

Create a Node 12 Function

Create a new package.json:

{
  "name": "ffnode12",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "functions-framework"
  },
  "dependencies": {
    "@google-cloud/functions-framework": "^1.2.1"
  }
}

Hard to make it simpler than that!

Create a class in greeter.js that uses Node 12 private fields:

class Greeter {
  #name = 'Functions Framework';
  get name() {
    return this.#name;
  }
  set name(name) {
    this.#name = name;
  }
  sayHello() {
    return `Hello, ${this.#name}`;
  }
}

module.exports = Greeter;

#private field

Create an index.js file:

const Greeter = require(‘./greeter’);

exports.function = (req, res) => {
const g = new Greeter();

// Can’t access private fields
// greet.#name = ‘NewName’;

res.send(g.sayHello());
};

Private fields are inaccessible!

Test the Functions Framework locally

You’ll want to test your service locally to ensure you code works.

So we got things working locally. But how do we deploy this to Google Cloud? Read on!

Next, we’ll use Cloud Build + Cloud Run

Create a Dockerfile

OK. I’ll be honest. If you asked me 6 months ago what Docker was, I’d mumble something about boxes, container ships, and a blue whale. But…

Docker is really nothing to be afraid of. It is an open platform for developing and running applications. To run an application, you’ll need to create some instructions for Docker to set up your environment.

Create a file called Dockerfile (no file extension) as such:

# Use the official Node.js 12 image.

https://hub.docker.com/_/node

FROM node:12

Create and change to the app directory.

WORKDIR /usr/src/app

Copy application dependency manifests to the container image.

A wildcard is used to ensure both package.json AND package-lock.json are copied.

Copying this separately prevents re-running npm install on every code change.

COPY package*.json ./

Install production dependencies.

RUN npm install --only=production

Copy local code to the container image.

COPY . .

Run the web service on container startup.

CMD [ “npm”, “start” ]

A basic Dockerfile for Node applications

We’ll tell Docker, use Node 12, copy our package.json we defined above, install, copy our files, then start our server!

Deploy to Cloud Run

To deploy to Google’s Cloud Run, follow these 3 steps:

1 - Setup gcloud

# Install gcloud beta services
gcloud components install beta# Set env var “GCP_PROJECT” to our project name
GCP_PROJECT=$(gcloud config list --format ‘value(core.project)’ 2>/dev/null)# Set our Cloud Run region (so we aren’t prompted)
gcloud config set run/region us-central1

2 - Upload your code and build the container

# Build and upload your image in Google Container Registry
gcloud builds submit --tag gcr.io/$GCP_PROJECT/helloworld

Notice each command in the Dockerfile gets executed (~30s)

3 - Deploy to Cloud Run

# Deploy your container to Cloud Run
gcloud beta run deploy --image gcr.io/$GCP_PROJECT/helloworld --platform managed

Deploy our container to Cloud Run (~17s)

You’ll get a URL that looks like this:

https://helloworld-q7vieseilq-uc.a.run.app

Congrats! You deployed the Functions Framework to Cloud Run.



#node-js #cloud #web-development #serverless #docker

What is GEEK

Buddha Community

Deploying a Node 12 Function to Cloud Run
Adaline  Kulas

Adaline Kulas

1594162500

Multi-cloud Spending: 8 Tips To Lower Cost

A multi-cloud approach is nothing but leveraging two or more cloud platforms for meeting the various business requirements of an enterprise. The multi-cloud IT environment incorporates different clouds from multiple vendors and negates the dependence on a single public cloud service provider. Thus enterprises can choose specific services from multiple public clouds and reap the benefits of each.

Given its affordability and agility, most enterprises opt for a multi-cloud approach in cloud computing now. A 2018 survey on the public cloud services market points out that 81% of the respondents use services from two or more providers. Subsequently, the cloud computing services market has reported incredible growth in recent times. The worldwide public cloud services market is all set to reach $500 billion in the next four years, according to IDC.

By choosing multi-cloud solutions strategically, enterprises can optimize the benefits of cloud computing and aim for some key competitive advantages. They can avoid the lengthy and cumbersome processes involved in buying, installing and testing high-priced systems. The IaaS and PaaS solutions have become a windfall for the enterprise’s budget as it does not incur huge up-front capital expenditure.

However, cost optimization is still a challenge while facilitating a multi-cloud environment and a large number of enterprises end up overpaying with or without realizing it. The below-mentioned tips would help you ensure the money is spent wisely on cloud computing services.

  • Deactivate underused or unattached resources

Most organizations tend to get wrong with simple things which turn out to be the root cause for needless spending and resource wastage. The first step to cost optimization in your cloud strategy is to identify underutilized resources that you have been paying for.

Enterprises often continue to pay for resources that have been purchased earlier but are no longer useful. Identifying such unused and unattached resources and deactivating it on a regular basis brings you one step closer to cost optimization. If needed, you can deploy automated cloud management tools that are largely helpful in providing the analytics needed to optimize the cloud spending and cut costs on an ongoing basis.

  • Figure out idle instances

Another key cost optimization strategy is to identify the idle computing instances and consolidate them into fewer instances. An idle computing instance may require a CPU utilization level of 1-5%, but you may be billed by the service provider for 100% for the same instance.

Every enterprise will have such non-production instances that constitute unnecessary storage space and lead to overpaying. Re-evaluating your resource allocations regularly and removing unnecessary storage may help you save money significantly. Resource allocation is not only a matter of CPU and memory but also it is linked to the storage, network, and various other factors.

  • Deploy monitoring mechanisms

The key to efficient cost reduction in cloud computing technology lies in proactive monitoring. A comprehensive view of the cloud usage helps enterprises to monitor and minimize unnecessary spending. You can make use of various mechanisms for monitoring computing demand.

For instance, you can use a heatmap to understand the highs and lows in computing visually. This heat map indicates the start and stop times which in turn lead to reduced costs. You can also deploy automated tools that help organizations to schedule instances to start and stop. By following a heatmap, you can understand whether it is safe to shut down servers on holidays or weekends.

#cloud computing services #all #hybrid cloud #cloud #multi-cloud strategy #cloud spend #multi-cloud spending #multi cloud adoption #why multi cloud #multi cloud trends #multi cloud companies #multi cloud research #multi cloud market

Adaline  Kulas

Adaline Kulas

1594166040

What are the benefits of cloud migration? Reasons you should migrate

The moving of applications, databases and other business elements from the local server to the cloud server called cloud migration. This article will deal with migration techniques, requirement and the benefits of cloud migration.

In simple terms, moving from local to the public cloud server is called cloud migration. Gartner says 17.5% revenue growth as promised in cloud migration and also has a forecast for 2022 as shown in the following image.

#cloud computing services #cloud migration #all #cloud #cloud migration strategy #enterprise cloud migration strategy #business benefits of cloud migration #key benefits of cloud migration #benefits of cloud migration #types of cloud migration

Thurman  Mills

Thurman Mills

1620721560

Cloud Deployment Models: Types of Models & Applications

What is Cloud Computing?

Cloud computing has emerged significantly over the past decade. The cloud deployment models essentially refer to how the servers are deployed and provisioned over the internet so that they can be accessed remotely by individuals and companies, without the need to configure them.

Why is Cloud Computing Becoming Popular?

Utilizing cloud deployment models provides multiple benefits like boosting productivity and providing a competitive advantage to organizations. With the growing popularity of cloud computing models, organizations are coming up with a variety of cloud deployment strategies designed to address specific infrastructure challenges that organizations face and the cloud computing solutions that they desire.

The different deployment strategies offer different levels of flexibility, cost-control, and data management within enterprises.

Cloud computing service models make it possible for companies to deploy and render several services, classified according to the roles, service providers, and user companies.

#cloud computing #cloud #cloud deployment #cloud deployment models

Thurman  Mills

Thurman Mills

1622206800

Develop and test Google Cloud Functions locally and deploy

A simple setup and template to manage, develop and deploy your Google Cloud Functions

I would like to describe here how I and my teammate Crosi found a way for us to develop Google Cloud Functions locally and then deploy them in an automated way using the Google Build service. We have read through countless documentations and would now like to compile our findings here.Currently, we are working on building a data lake. We were trying to find a way at the time that would allow us to develop Google Cloud Functions that would process files from Google Cloud Storage. Google allows writing the cloud function on a web interface within a Google code editor. However, it lacks trivial functions unlike a normal IDE like PyCharm. No code completion. No warnings. No local testing/execution before deployment. We wanted to face these issues.

Prerequisites

Your computer should have the Google Cloud SDK and git installed. I assume you have basic knowledge of Google Cloud Functions.

#cloud-storage #cloud-functions #google-cloud-platform #cloud

Mikel  Okuneva

Mikel Okuneva

1602882000

Firebase. Cloud Functions. Creation, deployment, and emulation

Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google’s cloud and runs in a managed environment. There’s no need to manage and scale your own servers.

What will be covered in this article

  • Set up Functions
  • Local setup
  • Deploying Functions
  • Emulating Functions
  • Other Firebase stories: BasicsAdmin SDK

Set up Functions

Before we can deploy our first Cloud Function we will need to Set up Functions in our Firebase project…

Image for post

Firebase will provide you steps for local installation, but this will be covered next, just click **Continue** …

Image for post

Image for post

We are ready for creating our first Cloud Function.

Image for post

#cloud #deploy #emulation #cloud-functions #firebase