此CI/CD配置文件无法直接创建lambda,可以在lambda创建后实现:
- 代码更新
- 版本发布
- 切换别名
Runner 需要安装如下库:
- aws cli
- python3.9
- zip
- jq
.gitlab-ci.yml
stages:
- archiving
- deploy
- publishVersion
- updateAlias
archive:
stage: archiving
script:
- python3.9 --version
- python3.9 -m pip install -r requirements.txt --target=.
- zip -r $CI_PROJECT_NAME.zip * -x .gitlab-ci.yml README.md requirements.txt
artifacts:
paths:
- $CI_PROJECT_NAME.zip
only:
- tags
deploy:
stage: deploy
script:
- aws --version
- aws lambda update-function-code --function-name $CI_PROJECT_NAME --zip-file fileb://$CI_PROJECT_NAME.zip
- sleep 30s
only:
- tags
publishVersion:
stage: publishVersion
script:
- echo `aws lambda publish-version --function-name $CI_PROJECT_NAME --description $CI_COMMIT_TAG | jq -r .Version` > version
- sleep 5s
artifacts:
paths:
- version
only:
- tags
updateAlias:
stage: updateAlias
script:
- aws lambda update-alias --function-name $CI_PROJECT_NAME --name prod --function-version $(cat version)
only:
- tags