일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- arm
- GCP
- openhack
- docker katacoda
- CI
- ADF
- Kubernetes
- Network Design
- Python
- 유럽
- 아시아
- pester
- aks
- 관심사
- DevOps
- BABOK
- azure governance
- install
- docker
- 데이터 엔지니어링
- Jenkins
- AZURE
- job
- CCBA
- ansible
- automation
- data factory
- PowerShell
- streaming
- packer
- Today
- Total
소소한 기록
Linux academy: Creating AWS Lambda Versions and Aliases via the AWS CLI 본문
Linux academy: Creating AWS Lambda Versions and Aliases via the AWS CLI
John C Kim 2019. 9. 27. 14:16Introduction
In this hands-on lab, we'll create Lambda function versions and aliases via the AWS CLI.
Solution
Open a terminal session, and log in to the server via SSH using the credentials provided on the lab page:
ssh cloud_user@<PUBLIC_IP_ADDRESS>
In the browser, log in to the live AWS environment using the credentials provided, and make sure you're in the N. Virginia (us-east-1) region.
All of the code used in the lesson is available for download here.
Lab Prep
- In AWS, navigate to IAM > Roles.
- Click the lambda_exec_role_LA role listed.
- Copy the ARN and paste it into a text file. We'll need it later.
-
In the terminal, make sure AWS CLI is installed by running:
aws helpYou should see it's installed.
Create Your Lambda Function
-
In the terminal, run:
vim lambda_function.py -
Paste in the code from GitHub.
- Save and exit the file.
-
Zip the file:
zip lambda_function.zip lambda_function.py -
Create the function (replacing <lambda_exec_role_LA_ARN> with the ARN you copied earlier):
aws lambda create-function --function-name SnapShot \ --description "Taking EBS Snaps" \ --memory-size 1024 \ --timeout 10 \ --handler lambda_function.handler \ --runtime "python3.6" \ --role "<lambda_exec_role_LA_ARN>" \ --zip-file fileb:///home/cloud_user/lambda_function.zip \ --region us-east-1
Publish Your First Version
-
Publish a new version:
aws lambda publish-version \ --function-name SnapShot \ --region us-east-1 -
Check the versions:
aws lambda list-versions-by-function \ --function-name SnapShot --region us-east-1
Create Your Alias
-
Create the alias:
aws lambda create-alias \ --function-name SnapShot \ --description "Production Alias" \ --function-version 1 \ --name PROD \ --region us-east-1 -
Check the aliases:
aws lambda list-aliases \ --function-name SnapShot \ --region us-east-1
Create Your CloudWatch Event Rule/Trigger
-
Add a permission for events to invoke the function alias:
aws lambda add-permission \ --function-name SnapShot \ --qualifier PROD \ --statement-id 001 \ --principal events.amazonaws.com \ --action lambda:InvokeFunction \ --region us-east-1 -
Copy the ARN listed in the output and paste it into a text file, as we'll need it later.
-
Create the CloudWatch rule:
aws events put-rule \ --name "EC2-SNAP" \ --schedule-expression "rate(2 minutes)" \ --state "ENABLED" \ --description "Takes EBS Snapshot of volumes on a scheduled basis." \ --region us-east-1 -
Add a target to the rule (replacing <PROD_ARN> with the one you copied a minute ago):
aws events put-targets \ --rule "EC2-SNAP" \ --targets "Id"="1","Arn"="<PROD_ARN>" \ --region us-east-1 -
Pause the rule:
aws events disable-rule \ --name EC2-SNAP \ --region us-east-1 -
Verify your output.
Publish a New Version and Remap Your Alias
-
Update the code:
vim lambda_function.py -
Paste in the updated code from GitHub.
- Save and exit the file.
-
Zip the file:
!zip zip lambda_function.zip lambda_function.py -
Upload your updated function code to Lambda:
aws lambda update-function-code \ --function-name SnapShot \ --zip-file fileb:///home/cloud_user/lambda_function.zip \ --region us-east-1 -
Publish a new version from that updated code base:
aws lambda publish-version \ --function-name SnapShot \ --region us-east-1 -
Once created, remap your alias to Version 2:
aws lambda update-alias \ --function-name SnapShot \ --name PROD \ --function-version 2 \ -
Check the alias:
aws lambda list-aliases \ --function-name SnapShot \ --region us-east-1 -
Re-enable the rule:
aws events enable-rule \ --name EC2-SNAP \ --region us-east-1