-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-lambda-TicketGenerationService.yml
More file actions
78 lines (61 loc) · 2.56 KB
/
Copy pathdeploy-lambda-TicketGenerationService.yml
File metadata and controls
78 lines (61 loc) · 2.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Deploy Python Lambda TicketGenerationService
on:
push:
branches:
- main
paths:
- 'services/TicketGenerationService/TicketGenerationService.py' # Change to the file extension of the language that you are using.
env:
AWS_REGION: eu-north-1 # set this to your preferred AWS region, e.g. us-west-1
S3_BUCKET: ticket-booking-services
S3_KEY: SeatReservationService_deployment_package.zip
LAMBDA_FUNCTION_NAME: TicketGenerationService
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 2 # To fetch the current commit and its parent (so we can compare)
- name: Setup AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }} # Modify this to your desired AWS region
- name: Print changed files # To properly debug what is being deployed (It can be removed).
run: |
echo "List of changed files:"
echo $(git diff --name-only HEAD^ HEAD)
- name: Deploy Modified Files
run: |
# Download the existing zip from S3
aws s3 cp s3://$S3_BUCKET/$S3_KEY existing_lambda.zip
# Unzip the existing package
unzip existing_lambda.zip -d lambda_env
# Copy only the modified .py files from the commit into the unzipped directory
# This will maintain their directory structure.
for file in $(git diff-tree --no-commit-id --name-only -r HEAD); do
if [[ $file == *.py ]]; then
# Create the directory structure in lambda_env for the modified file
mkdir -p lambda_env/$(dirname $file)
# Copy the modified file
cp $file lambda_env/$file
# Print what you've done with the file
echo "Copied $file to lambda_env/$file"
echo "Content of $file after copying:"
cat lambda_env/$file
fi
done
# Zip the directory again
cd lambda_env
zip -r ../updated_lambda.zip .
cd ..
# Upload the updated zip to S3
aws s3 cp updated_lambda.zip s3://$S3_BUCKET/$S3_KEY
# Update Lambda function code
aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --s3-bucket $S3_BUCKET --s3-key $S3_KEY
# Cleanup
rm -r lambda_env
rm existing_lambda.zip updated_lambda.zip