Aws cloudformation deploy lambda and apigateway

文章目录

  • 用Cloudformation 来部署 java 的lambda 和api gateway,这里要用到spring-boot写java 代码,需要用到s3,存放lambda代码,需要创建lambda function和api agetway,还需要用到sam

Aws lambda with Spring Boot

本文的步骤

  • 安装sam
  • git 克隆现有代码
  • 创建s3 bucket
  • 用cloudformation 上传 代码
  • 用cloudformation 部署
  • 测试代码

安装sam

1pip3 install --user aws-sam-cli

git 克隆代码

1git clone https://github.com/gemerick/spring-boot-lambda -b lambda
2
3mvn clean package

创建s3 bucket

1aws s3 mb s3://spring-boot-lambda-20100905

拷贝jar 到S3 ,更新sam的template

1aws cloudformation package --template-file sam.yaml --output-template-file target/output-sam.yaml --s3-bucket spring-boot-lambda-20100905

Deploy a Cloudformation stack from the SAM template

1aws cloudformation deploy --template-file target/output-sam.yaml --stack-name spring-boot-lambda --capabilities CAPABILITY_IAM
2
3aws cloudformation describe-stacks --stack-name spring-boot-lambda

测试部署结果

1curl   https://xxx.execute-api.ap-southeast-1.amazonaws.com/Prod/languages
2
3[{"name":"node"},{"name":"java"},{"name":"python"}]