Skip to content

Commit

Permalink
Add Github Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
reedshea committed Apr 17, 2024
1 parent c1ba965 commit 8c9d3b1
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy to AWS Lambda

on:
push:
branches:
- main

jobs:
deploy:
name: Deploy AWS Lambda Application
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Setup Python 3.12
uses: actions/setup-python@v5
with: { python-version: 3.12 }

- name: Install dependencies
run: pip install -r requirements.txt

- name: Run tests
run: pytest

- name: Set up 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: ${{ secrets.AWS_REGION }}

- name: Set up AWS SAM
uses: aws-actions/setup-sam@v2

- name: Build Lambda function
run: sam build --parallel

- name: Deploy to AWS Lambda
run: |
sam deploy --stack-name slackronym-production --capabilities CAPABILITY_IAM --no-confirm-changeset --no-fail-on-empty-changeset
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,46 @@ Tests are defined in the `tests` folder in this project.
```bash
slackronym$ pytest
```


## Deploy the sample application using GitHub Actions

* Create a user in AWS IAM. Save the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` in GitHub Actions Secrets.
* Create another GitHub Actions Secret for `AWS_REGION`, like `us-east-1`
* Attach an IAM policy to the user that is similar to the JSON below (or ideally more tightly scoped):

```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"iam:AttachRolePolicy",
"iam:CreateRole",
"iam:DeleteRole",
"iam:DetachRolePolicy",
"iam:PassRole",
"iam:GetRole",
"iam:PutRolePolicy",
"iam:TagRole",
"cloudformation:CreateChangeSet",
"cloudformation:DeleteStack",
"cloudformation:DescribeStacks",
"cloudformation:UpdateStack",
"cloudformation:CreateStack",
"cloudformation:ExecuteChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:DescribeStackEvents",
"s3:CreateBucket",
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"lambda:*"
],
"Resource": "*"
}
]
}
```

0 comments on commit 8c9d3b1

Please sign in to comment.