Skip to content

Commit

Permalink
feat(action-aws): add lambda-deploy action
Browse files Browse the repository at this point in the history
  • Loading branch information
JoffreyPlouvier committed Mar 24, 2023
1 parent d322bc3 commit 3f7fe35
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions actions/aws/lambda-deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# AWS: lambda-deploy

## Behavior

Download specified artifact.
Connect to AWS.
Update the lambda code and publish a new version

## Usage

```yaml
jobs:
deploy-lambda:
runs-on: ubuntu-latest
steps:
- name: "Checkout Code"
uses: "actions/checkout@v2"

- name: "Deploy"
uses: "meero-com/github-actions-shared-workflows/actions/aws/lambda-deploy@main"
with:
artifact_name: image-uri
artifact_filename: image-uri.txt
AWS_ACCESS_KEY_ID: ${{ secrets.NP_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.NP_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
LAMBDA_FUNCTION_NAME: my-wonderful-lambda
```
Beware of using a `@ref` (`@main` in the example above) which suits your stability requirements in your workflow:

* Use `@main` if you always want to use the latest version of the workflow.
* Use `@<tag>` if you wan to use a specific frozen version of the workflow.
54 changes: 54 additions & 0 deletions actions/aws/lambda-deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Deploy Lambda"
description: "Deploy the Lambda Function"

inputs:
AWS_ACCESS_KEY_ID:
description: "Aws access key"
required: true
AWS_SECRET_ACCESS_KEY:
description: "AWS secret"
required: true
AWS_REGION:
description: "AWS region"
required: true
LAMBDA_FUNCTION_NAME:
description: "Lambda function name"
required: true
artifact_name:
description: "name of Image artifact (container) to deploy"
required: true
artifact_filename:
description: "filename of Image artifact (container) to deploy"
required: true

runs:
using: "composite"
steps:
- name: Fetch Image URI artifact
uses: actions/download-artifact@v2
with:
name: ${{ inputs.artifact_name }}

- name: Set variable image from artifact (image URI)
shell: bash
id: vars
run: echo "image=$(cat ${{ inputs.artifact_filename }})" >> $GITHUB_OUTPUT

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ inputs.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ inputs.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ inputs.AWS_REGION }}

- name: Update the Lambda code (new Docker image)
shell: bash
env:
IMAGE_URI: ${{ steps.vars.outputs.image }}
LAMBDA_FUNCTION_NAME: ${{ inputs.LAMBDA_FUNCTION_NAME }}
run: |
aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --image-uri $IMAGE_URI
aws lambda wait function-updated --function-name $LAMBDA_FUNCTION_NAME
result=$(aws lambda publish-version --function-name $LAMBDA_FUNCTION_NAME)
version=$(echo ${result}| jq -r .Version)
echo "Deployed version ${version} of the lambda $LAMBDA_FUNCTION_NAME"

0 comments on commit 3f7fe35

Please sign in to comment.