Skip to content

axel-op/package-java-aws-lambda

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Package an AWS Lambda in Java

A GitHub Action to package an AWS Lambda in Java with Maven.

AWS Lambdas in Java should be packaged as an Uber JAR.

The maven-shade-plugin is used to build the Uber JAR. While configuring it in the pom.xml is the recommended way to use it, here we execute it from the command line so the pom.xml doesn't have to be edited.

Inputs/Outputs

  • The input working-directory is optional and indicates where is the root directory of your Lambda function.
  • The output deployment-file is an absolute path to the JAR that should be deployed (see the example below).

Example workflow

This GitHub Actions workflow shows how to deploy an AWS Lambda using the UpdateFunctionCode API with the aws CLI:

name: Example workflow

on:
  push:
    branches:
      - main

jobs:
  deploy-aws-lambda:
    runs-on: ubuntu-latest
    permissions:
      # This is required for requesting GitHub's OIDC Token
      # See https://github.com/aws-actions/configure-aws-credentials
      id-token: write
    env:
      REGION: eu-west-3
      FUNCTION_NAME: name-of-function
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v2
        with:
          java-version: 11
          distribution: adopt
      - uses: axel-op/package-java-aws-lambda@main
        id: package
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: ${{ secrets.AWS_ROLE }}
          aws-region: ${{ env.REGION }}
      - name: Deploy on AWS
        env:
          JAR: ${{ steps.package.outputs.deployment-file }}
        run: aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file "fileb://$JAR"

The AWS documentation describes all the possible ways to deploy your function.