Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.12 KB

ex16-5.md

File metadata and controls

54 lines (37 loc) · 1.12 KB

16.5 Developing with Serverless (Cloud Run)

Example: create service account

gcloud iam service-accounts create api-cloud-run-invoker \
   --display-name "My Cool Service Account"

Example: Permissions

gcloud run services add-iam-policy-binding api-service \
  --member=serviceAccount:api-cloud-run-invoker@$GOOGLE_CLOUD_PROJECT.iam.gserviceaccount.com \
  --role=roles/run.invoker --platform managed

Example: API's

const express = require('express');
const PORT = process.env.PORT || 8080;
const app = express();

app.use(express.json());

app.listen(PORT, () => {
  console.log(`Simple REST API listening on port ${PORT}`);
});

app.get('/', async (req, res) => {
  return res.status(200).json({'Status':'OK', 'Payload':'GET: Up and Running'});
})

app.post('/', async (req, res) => {
  return res.status(200).json({'Status':'OK', 'Payload':'POST: Up and Running'});
})

Example: Container Image

gcloud beta run deploy api-service \
   --image gcr.io/[PROJECT_ID/api-service-image:latest

Example : interact

curl --request GET [CLOUD_RUN_ENDPOINT]