Skip to content

Commit dcf3034

Browse files
authored
Merge pull request #12 from aws-actions/initial
build: Initial commit
2 parents 23208dd + 319493d commit dcf3034

12 files changed

+648
-1135
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ updates:
55
schedule:
66
interval: weekly
77
day: tuesday
8-
open-pull-requests-limit: 10
8+
open-pull-requests-limit: 10
9+
commit-message:
10+
prefix: "chore:"

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ dist
33
.DS_Store
44
coverage
55
repolinter
6-
deploy-lambda.yml
76
Config

README.md

Lines changed: 74 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Updates the code and configuration of AWS Lambda functions
77
<!-- toc -->
88

99
- [Usage](#usage)
10+
* [Update Function Configuration](#update-configuration-only)
1011
* [Using S3 Deployment Method](#using-s3-deployment-method)
11-
* [Update Configuration Only](#update-configuration-only)
1212
* [Dry Run Mode](#dry-run-mode)
13+
- [Build from Source](#build-from-source)
1314
- [Inputs](#inputs)
1415
- [Outputs](#outputs)
1516
- [Credentials and Region](#credentials-and-region)
16-
* [OpenID Connect (OIDC) - Recommended Approach](#openid-connect-oidc---recommended-approach)
1717
- [Permissions](#permissions)
1818
- [License Summary](#license-summary)
1919
- [Security Disclosures](#security-disclosures)
@@ -23,124 +23,105 @@ Updates the code and configuration of AWS Lambda functions
2323
## Usage
2424

2525
```yaml
26-
name: Deploy Lambda Function
26+
name: Deploy to AWS Lambda
2727

2828
on:
2929
push:
30-
branches: [main, master]
30+
branches: [ "main" ]
31+
32+
permissions:
33+
id-token: write # This is required for OIDC authentication
34+
contents: read # This is required to checkout the repository
3135

3236
jobs:
3337
deploy:
38+
name: Deploy
3439
runs-on: ubuntu-latest
35-
permissions:
36-
id-token: write # Required for OIDC authentication
37-
contents: read # Required to check out the repository
40+
environment: production
41+
3842
steps:
39-
- uses: actions/checkout@v3
40-
41-
- name: Configure AWS credentials
42-
uses: aws-actions/configure-aws-credentials@v2
43-
with:
44-
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
45-
- name: Deploy Lambda function
46-
uses: aws-actions/amazon-lambda-deploy@v1
47-
with:
48-
function-name: my-lambda-function
49-
code-artifacts-dir: ./dist
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Configure AWS credentials
47+
uses: aws-actions/configure-aws-credentials@v3
48+
with:
49+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
50+
aws-region: ${{ env.AWS_REGION }}
51+
# The role-to-assume should be the ARN of the IAM role you created for GitHub Actions OIDC
52+
53+
- name: Deploy Lambda Function
54+
uses: aws-actions/aws-lambda-deploy@v1
55+
with:
56+
function-name: my-function-name
57+
code-artifacts-dir: my-code-artifacts-dir
58+
# handler: my-handler
59+
# runtime: my-runtime
60+
# Add any additional inputs your action supports
5061
```
5162

52-
### Using S3 Deployment Method
63+
The required parameters to deploy are function name, code artifacts directory, handler, and runtime. The function name and code artifacts directory need to be provided by the user. However, the handler and runtime do not and will default to index.handler and nodejs20.x if not provided.
64+
65+
### Update Function Configuration
5366

5467
```yaml
55-
name: Deploy Lambda Function with S3
68+
- name: Update Lambda configuration
69+
uses: aws-actions/aws-lambda-deploy@v1
70+
with:
71+
function-name: my-function-name
72+
code-artifacts-dir: my-code-artifacts-dir
73+
memory-size: 512
74+
timeout: 60
75+
environment: '{"ENV":"production","DEBUG":"true"}'
76+
```
5677
57-
on:
58-
push:
59-
branches: [main, master]
78+
### Using S3 Deployment Method
6079
61-
jobs:
62-
deploy:
63-
runs-on: ubuntu-latest
64-
permissions:
65-
id-token: write # Required for OIDC authentication
66-
contents: read # Required to check out the repository
67-
steps:
68-
- uses: actions/checkout@v3
69-
70-
- name: Configure AWS credentials with OIDC
71-
uses: aws-actions/configure-aws-credentials@v2
72-
with:
73-
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
74-
80+
```yaml
7581
- name: Deploy Lambda function via S3
76-
uses: aws-actions/amazon-lambda-deploy@v1
82+
uses: aws-actions/aws-lambda-deploy@v1
7783
with:
78-
function-name: my-lambda-function
79-
code-artifacts-dir: ./dist
80-
s3-bucket: my-lambda-deployment-bucket
84+
function-name: my-function-name
85+
code-artifacts-dir: my-code-artifacts-dir
86+
s3-bucket: my-s3-bucket
8187
# s3-key is optional - a key will be auto-generated if not specified
8288
```
8389

84-
### Update Configuration Only
90+
### Dry Run Mode
8591

8692
```yaml
87-
name: Update Lambda Configuration
88-
89-
on:
90-
push:
91-
branches: [main, master]
92-
93-
jobs:
94-
deploy:
95-
runs-on: ubuntu-latest
96-
permissions:
97-
id-token: write # Required for OIDC authentication
98-
contents: read # Required to check out the repository
99-
steps:
100-
- uses: actions/checkout@v3
101-
102-
- name: Configure AWS credentials with OIDC
103-
uses: aws-actions/configure-aws-credentials@v2
104-
with:
105-
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
106-
- name: Update Lambda configuration
107-
uses: aws-actions/amazon-lambda-deploy@v1
93+
- name: Deploy on dry run mode
94+
uses: aws-actions/aws-lambda-deploy@v1
10895
with:
109-
function-name: my-lambda-function
110-
code-artifacts-dir: ./dist
111-
memory-size: 512
112-
timeout: 60
113-
environment: '{"ENV":"production","DEBUG":"true"}'
96+
function-name: my-function-name
97+
code-artifacts-dir: my-code-artifacts-dir
98+
dry-run: true
11499
```
100+
## Build from Source
115101
116-
### Dry Run Mode
102+
To automate building your source code, add a build step based on your runtime and build process. Below are two commonly used examples for Node.js and Python:
103+
104+
### Node.js
117105
118106
```yaml
119-
name: Validate Lambda Deployment
107+
- name: Build source code
108+
run: |
109+
# Install dependencies
110+
npm ci
120111
121-
on:
122-
pull_request:
123-
branches: [main, master]
112+
# Build
113+
npm run build
114+
```
115+
### Python
124116
125-
jobs:
126-
validate:
127-
runs-on: ubuntu-latest
128-
permissions:
129-
id-token: write # Required for OIDC authentication
130-
contents: read # Required to check out the repository
131-
steps:
132-
- uses: actions/checkout@v3
133-
134-
- name: Configure AWS credentials with OIDC
135-
uses: aws-actions/configure-aws-credentials@v2
136-
with:
137-
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
138-
- name: Validate Lambda deployment (no changes)
139-
uses: aws-actions/amazon-lambda-deploy@v1
140-
with:
141-
function-name: my-lambda-function
142-
code-artifacts-dir: ./dist
143-
dry-run: true
117+
```yaml
118+
- name: Build source code using setup tools
119+
run: |
120+
# Install dependencies
121+
pip install -r requirement.txt
122+
123+
# Build
124+
python -m build
144125
```
145126
146127
## Inputs
@@ -187,32 +168,17 @@ jobs:
187168

188169
This action relies on the [default behavior of the AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) to determine AWS credentials and region. Use the [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) action to configure the GitHub Actions environment for AWS authentication.
189170

190-
### OpenID Connect (OIDC) - Recommended Approach
171+
### OpenID Connect (OIDC)
191172

192173
We **highly recommend** using OpenID Connect (OIDC) to authenticate with AWS. OIDC allows your GitHub Actions workflows to access AWS resources without storing AWS credentials as long-lived GitHub secrets.
193174

194175
Here's an example of using OIDC with the aws-actions/configure-aws-credentials action:
195176

196177
```yaml
197-
jobs:
198-
deploy:
199-
runs-on: ubuntu-latest
200-
permissions:
201-
id-token: write # Required for OIDC authentication
202-
contents: read # Required to check out the repository
203-
steps:
204-
- uses: actions/checkout@v3
205-
206178
- name: Configure AWS credentials with OIDC
207179
uses: aws-actions/configure-aws-credentials@v2
208180
with:
209181
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
210-
211-
- name: Deploy Lambda function
212-
uses: aws-actions/amazon-lambda-deploy@v1
213-
with:
214-
function-name: my-lambda-function
215-
code-artifacts-dir: ./dist
216182
```
217183

218184
To use OIDC authentication, you must configure a trust policy in AWS IAM that allows GitHub Actions to assume an IAM role. Here's an example trust policy:

0 commit comments

Comments
 (0)