Deploy Go AWS Lambdas with GitHub Actions
How to Deploy Golang AWS Lambda using Github Actions
How to Deploy Golang AWS Lambda using Github Actions
In this article, we will be explaining how to deploy your Golang AWS Lambda functions using GitHub Actions. This process will automate the deployment of your functions and make it a lot easier for you to keep your functions up-to-date.
Step 1: Checkout
The first step in our Github Actions workflow is to checkout your repository. This step is performed using the actions/checkout@v3 action. This action checks out the repository so that we can build and deploy the code.
- name: Checkout
uses: actions/checkout@v3
**Step 2: Set up Go**
Next, we will set up the Go programming language. This step is performed using the `actions/setup-go@v3` action. In this step, you can specify the version of Go you want to use. For this example, we are using version 1.16.
yaml
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.16Step 3: Build
In this step, we will build the Golang code that will be deployed to the AWS Lambda function. To do this, we will use the Go build command and specify the main.go file. The working directory should be set to the location of your code.
- name: Build
working-directory: ./lambda/<function-name>
run: go build -v main.goStep 4: Zip
Next, we will zip the build file so it can be uploaded to AWS Lambda. We will use the zip command and specify the build file to do this. The working directory should be set to the location of your code.
- name: Zip
working-directory: ./lambda/<function-name>
run: zip -j deploy.zip mainStep 5: Configure AWS Credentials
Now that our code is ready to be deployed, we will configure the AWS credentials. This step is performed using the aws-actions/configure-aws-credentials@v1 action. In this step, you will need to specify your AWS access key ID, AWS secret access key, and the AWS region. These values can be stored as secrets in your GitHub repository.
- name: Configure AWS Credentials
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: eu-central-1Step 6: Upload Zip
The final step is to upload the zip file to AWS Lambda. To do this, we will use the AWS CLI command to update the function code. The working directory should be set to the location of your code.
- name: Upload Zip
working-directory: ./lambda/<function-name>
run: aws lambda update-function-code --function-name <function-name> --zip-file fileb://deploy.zipFull Code:
jobs:
Deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.16
- name: Build
working-directory: ./lambda/<function-name>
run: go build -v main.go
- name: Zip
working-directory: ./lambda/<function-name>
run: zip -j deploy.zip main
- name: Configure AWS Credentials
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: eu-central-1
- name: Upload Zip
working-directory: ./lambda/<function-name>
run: aws lambda update-function-code --function-name <function-name> --zip-file fileb://deploy.zipOnce more than one function is involved, the template stops being small. AWS Nested Stacks for Serverless Deployments splits it up, and AWS SAM parameter_overrides keeps dev and prod apart.
AuraLyrics
If you listen to music while you write code, AuraLyrics puts the lyrics over your editor instead of behind another window.
brew install --cask ozcberkay/tap/auralyricsNotes like this one, once a month
Java, AWS and what shipping a side product actually costs.