$ node -v
v5.12.0
$ npm install -g serverless
$ serverless —version
1.5.1
$ 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 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
serverless.yml
provider:
name: aws
runtime: java8
stage: prod
region: ap-northeast-1
$ 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
J'aimerais jusqu'à présent configurer Lambda sur la console et télécharger Jar.
Vérifiez si Lambda répond avec la commande invoke.
$ 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
}
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...
Recommended Posts