-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (82 loc) · 2.88 KB
/
deploy-app.yml
File metadata and controls
106 lines (82 loc) · 2.88 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: deploy app
on:
push:
branches: [main]
env:
AWS_REGION: eu-west-2
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: eu-west-2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'src/handler/package.json'
- name: Install dependencies
working-directory: "./src/handler"
run: npm ci --production
- name: Package Lambda function
run: |
cd src/handler
zip -r ../../deployment.zip .
- name: Get artifacts bucket name
id: bucket
run: |
BUCKET=$(aws s3api list-buckets \
--query "Buckets[?starts_with(Name, 'node-api-dev-lambda-artifacts')].Name" \
--output text)
echo "name=${BUCKET}" >> $GITHUB_OUTPUT
echo "Using bucket: ${BUCKET}"
- name: Upload to S3
run: |
aws s3 cp deployment.zip \
s3://${{ steps.bucket.outputs.name }}/deployment.zip \
--metadata "git-commit=${{ github.sha }},git-branch=${{ github.ref_name }},deployed-by=github-actions"
echo "Uploaded deployment package to S3"
- name: Update Lambda function code
id: update-lambda
run: |
FUNCTION_NAME="node-api-dev-api"
echo "Updating Lambda function: ${FUNCTION_NAME}"
aws lambda update-function-code \
--function-name ${FUNCTION_NAME} \
--s3-bucket ${{ steps.bucket.outputs.name }} \
--s3-key deployment.zip \
--publish
echo "Waiting for function update to complete..."
aws lambda wait function-updated \
--function-name ${FUNCTION_NAME}
VERSION=$(aws lambda get-function \
--function-name ${FUNCTION_NAME} \
--query 'Configuration.Version' \
--output text)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Lambda updated to version: ${VERSION}"
- name: Get API endpoint
id: api
run: |
API_ID=$(aws apigatewayv2 get-apis \
--query "Items[?Name==\`node-api-dev-api\`].ApiId" \
--output text)
if [ -z "$API_ID" ] || [ "$API_ID" == "None" ]; then
echo "ERROR: API 'node-api-dev-api' not found."
exit 1
fi
ENDPOINT=$(aws apigatewayv2 get-api \
--api-id "$API_ID" \
--query 'ApiEndpoint' \
--output text)
echo "endpoint=${ENDPOINT}" >> $GITHUB_OUTPUT
echo "API endpoint: $ENDPOINT"