-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (43 loc) · 1.89 KB
/
Copy pathdeploy-lambda.yml
File metadata and controls
55 lines (43 loc) · 1.89 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Deploy Lambda to AWS
on:
push:
branches:
- main # Change to your working branch if needed
paths:
- 'lambda_function.py' # Only trigger on changes to this file
- '.github/workflows/deploy-lambda.yml' # Trigger on workflow file changes
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout code
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
# Step 4: Zip the Lambda function code
- name: Zip Lambda function
run: zip -r lambda_function.zip lambda_function.py
# Step 5: Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1 # Change if you used a different region
# Step 6: Upload ZIP to S3
- name: Upload ZIP to S3
run: aws s3 cp lambda_function.zip s3://${{secrets.LAMBDA_CODE_BUCKET_NAME}}/lambda_function.zip
# Step 7: Update Lambda function
- name: Update Lambda function code
run: aws lambda update-function-code --function-name cloudtrail_logger --s3-bucket ${{secrets.LAMBDA_CODE_BUCKET_NAME}} --s3-key lambda_function.zip
- name: wait for Lambda function to be ready
run: aws lambda wait function-updated --function-name cloudtrail_logger
- name: Update Lambda function configuration
run: aws lambda update-function-configuration --function-name cloudtrail_logger --environment "Variables={SNS_TOPIC_ARN=${{secrets.SNS_TOPIC_ARN}}}"
# Step 8: Optional - Clean up local zip file
- name: Cleanup
run: rm lambda_function.zip