Serverless Framework라면 바로 할 수 있네요 AWS에서 서버리스(API+Lambda[java]를 간단 셋업)
소개
Serverless Conf Tokyo 의 자신의 등단에 하지만 건드리지만, Serverless로 하고 있으면 코드나 Build+Deploy의 관리가 엉망이 되어, 메인터넌스성이 부족하기 쉽습니다.
License은 MIT License입니다.
h tp // w w. s에서 멋지다. 네 t / 케이스 케 69 / 츠네 우 푸아 ws-mb
환경 설정
Serverless Framework 설치
$ node -v
v5.12.0
$ npm install -g serverless
$ serverless —version
1.5.1
AWS CLI 설정
$ pip install awscli
$ aws configure
AWS Access Key ID [None]:(Access Key)
AWS Secret Access Key [None]:(Secret Key)
Default region name [None]: ap-northeast-1
Default output format [None]:json
Serverless Framework에서 Deploy
서비스 만들기
$ serverless create --template aws-java-maven --path myService
・
・
Serverless: Successfully generated boilerplate for template: "aws-java-maven"
Serverless: NOTE: Please update the "service" property in serverless.yml with your service name
STS (Eclipse)로 가져 오기
serverless.yml 수정 + Build
serverless.yml
provider:
name: aws
runtime: java8
stage: prod
region: ap-northeast-1
Deploy 그 1(Lambda만)
$ cd myService
$ serverless deploy -v
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (1.98 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - aws-java-maven-prod
・
・
Serverless: Stack update finished...
Service Information
service: aws-java-maven
stage: prod
region: ap-northeast-1
api keys:
None
endpoints:
None
functions:
aws-java-maven-prod-hello: arn:XXXXXXXX
$ echo '{"key1":"value1","key2":"value2","key3":"value3"}' > event.json
$ serverless invoke --function hello -p event.json
{
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v1.x! Your function executed successfully!\",\"input\":{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}}",
"headers": {
"X-Powered-By": "AWS Lambda & serverless"
},
"isBase64Encoded": false
}
Deploy 그 2(API Gateway+Lambda)
serverless.yml
functions:
hello:
handler: com.serverless.Handler
events:
- http:
path: users/create
method: get
$ serverless deploy -v
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (1.98 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - aws-java-maven-prod
・
・
Service Information
service: aws-java-maven
stage: prod
region: ap-northeast-1
api keys:
None
endpoints:
GET - https://XXXXXXXX.execute-api.ap-northeast-1.amazonaws.com/prod/users/create
functions:
aws-java-maven-prod-hello: arn:XXXXXXXX
$ curl https://XXXXXXXX.execute-api.ap-northeast-1.amazonaws.com/prod/users/create
{"message":"Go Serverless v1.x! Your function executed successfully!","input":{"resource":"/users/create","path":"/users/create","httpMethod":"GET","headers":{"Accept":"*/*","CloudFront-Forwarded-Proto":"https","CloudFront-Is-Desktop-Viewer":"true","CloudFront-Is-Mobile-Viewer":
・
・
스택 삭제
$ serverless remove
Serverless: Getting all objects in S3 bucket...
Serverless: Removing objects in S3 bucket...
Serverless: Removing Stack...
Serverless: Checking Stack removal progress...
.....................
Serverless: Stack removal finished...
요약
Reference
이 문제에 관하여(Serverless Framework라면 바로 할 수 있네요 AWS에서 서버리스(API+Lambda[java]를 간단 셋업)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ukitiyan/items/945d84282726d3fe2c2f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)