Last active
April 7, 2021 18:09
-
-
Save camdenfullmer/6ed180662017cc8b17fdd641f83892e5 to your computer and use it in GitHub Desktop.
GitHub workflow to deploy an AWS Lambda function using the Swift AWS Lambda Runtime (https://github.com/swift-server/swift-aws-lambda-runtime). Found this necessary since there are issues building/running x86 Docker containers on a M1 MacBook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM swift:5.3-amazonlinux2 | |
RUN yum -y install zip openssl-devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Taken from: https://github.com/swift-server/swift-aws-lambda-runtime/blob/main/Examples/LambdaFunctions/scripts/package.sh | |
##===----------------------------------------------------------------------===## | |
## | |
## This source file is part of the SwiftAWSLambdaRuntime open source project | |
## | |
## Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | |
## Licensed under Apache License v2.0 | |
## | |
## See LICENSE.txt for license information | |
## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | |
## | |
## SPDX-License-Identifier: Apache-2.0 | |
## | |
##===----------------------------------------------------------------------===## | |
set -eu | |
executable=$1 | |
target=".build/lambda/$executable" | |
rm -rf "$target" | |
mkdir -p "$target" | |
cp ".build/release/$executable" "$target/" | |
# add the target deps based on ldd | |
ldd ".build/release/$executable" | grep swift | awk '{print $3}' | xargs cp -Lv -t "$target" | |
cd "$target" | |
ln -s "$executable" "bootstrap" | |
zip --symlinks lambda.zip * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy-swift-aws-lambda-runtime | |
on: | |
push: | |
branches: [ master, dev ] | |
pull_request: | |
branches: [ master ] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
env: | |
APP_NAME: HelloWorld | |
S3_BUCKET: MyBucket | |
LAMBDA_FUNCTION_NAME: HelloWorld | |
steps: | |
- uses: actions/checkout@v2 | |
- name: 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_ACCESS_KEY_SECRET }} | |
aws-region: us-east-1 | |
- name: Docker Image | |
run: docker build -f $GITHUB_WORKSPACE/Dockerfile -t lambda-runtime . | |
- name: Build | |
run: docker run -t --rm -w /build -v $GITHUB_WORKSPACE:/build lambda-runtime swift build -c release -Xswiftc -g | |
- name: Package | |
run: docker run -t --rm -w /build -v $GITHUB_WORKSPACE:/build lambda-runtime bash -cl "./package.sh $APP_NAME" | |
- name: S3 | |
run: aws s3 cp $GITHUB_WORKSPACE/.build/lambda/$APP_NAME/lambda.zip s3://$S3_BUCKET/$APP_NAME.zip | |
- name: Lambda | |
run: aws lambda update-function-code --function $LAMBDA_FUNCTION_NAME --s3-bucket $S3_BUCKET --s3-key $APP_NAME.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment