brunch

You can make anything
by writing

C.S.Lewis

by Master Seo May 18. 2020

123. Cloud Function - CLI

1. cli 환경 확인하기

gcloud config list 



변경

gcloud config set compute/zone us-central1-a 


변경

gcloud config  set  project www-serverchk-com


gcloud auth list

gcloud config list project



2. 함수 만들기

Cloud Shell 명령줄에서 함수 코드용 디렉토리를 만듭니다.

mkdir hello 


vi  index.js

exports.helloWorld = function helloWorld (event, callback) { console.log(`My Cloud Function: ${JSON.stringify(event.data.message)}`);   

callback(); }; 



3.  Cloud Storage 버킷을 만듭니다.

gsutil mb -p [프로젝트_ID] gs://[버킷_이름]
  

gsutil mb -p seo-pj-277509 gs://seo3-bucket



4. 함수 배포
  

hello_world 이름의 Pub/Sub 함수 배포


gcloud functions deploy helloWorld --stage-bucket [버킷_이름] --trigger-topic hello_world  --runtime nodejs6 


gcloud functions deploy helloWorld --stage-bucket seo3-bucket --trigger-topic hello_world  --runtime nodejs10

(2분 걸림)


함수 상태 확인.    

gcloud functions describe helloWorld   

status: ACTIVE 인지 확인


주제에 게시된 모든 메시지는 함수 실행을 트리거하며, 메시지 내용은 입력 데이터로서 전달됩니다.



5. 완료된 작업 테스트하기

입력하기

gcloud functions call helloWorld --data '{"message":"Hello World!"}'


ERROR   ???

error: |-  Error: function execution failed. Details:  Cannot read property 'message' of undefined



6. 로그 보기

gcloud functions logs read helloWorld




감사합니다.

keyword
매거진의 이전글 122. Cloud Functions - Console

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari