diff --git a/.github/workflows/deploy-lambda.yaml b/.github/workflows/deploy-lambda.yaml new file mode 100644 index 0000000..fb89150 --- /dev/null +++ b/.github/workflows/deploy-lambda.yaml @@ -0,0 +1,79 @@ +name: Deploy Lambda to AWS + +on: + push: + branches: ["*-workshop"] + paths: + - .github/** + - lambda/** + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + AWS_REGION: eu-west-1 + +jobs: + deploy: + runs-on: ubuntu-latest + env: + FUNCTION_NAME: ${{ github.ref_name }} + permissions: + id-token: write + contents: read + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v6 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 24 + cache: npm + cache-dependency-path: lambda/package-lock.json + - name: Install dependencies + working-directory: ./lambda + run: npm ci + - name: Build TypeScript + working-directory: ./lambda + run: npm run build + - name: Deploy to Lambda + uses: aws-actions/aws-lambda-deploy@v1 + with: + function-name: ${{ env.FUNCTION_NAME }} + function-description: "Workshop Lambda deployed by ${{ github.actor }}" + code-artifacts-dir: ./lambda + handler: build/index.handler + runtime: nodejs24.x + - name: Test Lambda function + run: | + echo "๐Ÿงช Testing Lambda function..." + aws lambda invoke \ + --function-name ${{ env.FUNCTION_NAME }} \ + --payload '{}' \ + --log-type Tail \ + response.json + + echo "๐Ÿ“‹ Lambda response:" + cat response.json + - name: Get CloudWatch logs + run: | + echo "๐Ÿ“œ Fetching CloudWatch logs..." + LOG_STREAM=$(aws logs describe-log-streams \ + --log-group-name /aws/lambda/${{ env.FUNCTION_NAME }} \ + --order-by LastEventTime \ + --descending \ + --max-items 1 \ + --query 'logStreams[0].logStreamName' \ + --output text) + + aws logs get-log-events \ + --log-group-name /aws/lambda/${{ env.FUNCTION_NAME }} \ + --log-stream-name "$LOG_STREAM" \ + --limit 20 \ + --output table