|
| 1 | +# 🚀 Lambda Restart |
| 2 | +Update an AWS Lambda function to a new container image (ECR). Supports direct `image_uri` or `repository` + `image_tag`, OIDC or static AWS credentials, and optional wait for completion. |
| 3 | + |
| 4 | +## ✅ Features |
| 5 | +- Update Lambda to a specific container image (ECR) |
| 6 | +- Accept either full `image_uri` or `repository` + `image_tag` |
| 7 | +- AWS auth via OIDC role assumption or static credentials |
| 8 | +- Validates Lambda existence before update |
| 9 | +- Optional wait until function update completes |
| 10 | +- Summary output with key details |
| 11 | + |
| 12 | +## 📖 Related Documentation |
| 13 | +- AWS Lambda container images: https://docs.aws.amazon.com/lambda/latest/dg/images-create.html |
| 14 | +- Update function code (CLI): https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html |
| 15 | +- ECR repositories and images: https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html |
| 16 | +- GitHub OIDC for AWS: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html |
| 17 | + |
| 18 | +## 🚀 Prerequisites |
| 19 | +Your workflow must: |
| 20 | +- Run on `ubuntu-latest` with AWS CLI and `jq` available |
| 21 | +- Provide AWS credentials or an assumable IAM role |
| 22 | +- Ensure the target ECR image exists and the Lambda function is configured for images |
| 23 | + |
| 24 | +## 🔧 Quick Example |
| 25 | +```yaml |
| 26 | +name: Restart Lambda |
| 27 | + |
| 28 | +on: |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +jobs: |
| 32 | + update: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + permissions: |
| 35 | + id-token: write |
| 36 | + contents: read |
| 37 | + steps: |
| 38 | + - name: Update Lambda to specific image URI (OIDC) |
| 39 | + uses: Mad-Pixels/github-workflows/actions/lambda-restart@v1 |
| 40 | + with: |
| 41 | + aws_region: us-east-1 |
| 42 | + aws_account_id: 123456789012 |
| 43 | + role_to_assume: arn:aws:iam::123456789012:role/GHA-OIDC |
| 44 | + function_name: my-service-prod |
| 45 | + image_uri: 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-service@sha256:deadbeef |
| 46 | + wait_for_update: 'true' |
| 47 | + |
| 48 | + # Alternative: use repository + tag instead of full image_uri |
| 49 | + # - name: Update Lambda with repository/tag |
| 50 | + # uses: Mad-Pixels/github-workflows/actions/lambda-restart@v1 |
| 51 | + # with: |
| 52 | + # aws_region: us-east-1 |
| 53 | + # aws_account_id: 123456789012 |
| 54 | + # role_to_assume: arn:aws:iam::123456789012:role/GHA-OIDC |
| 55 | + # function_name: my-service-prod |
| 56 | + # repository: my-service |
| 57 | + # image_tag: latest |
| 58 | + # wait_for_update: 'true' |
| 59 | +``` |
| 60 | + |
| 61 | +## 📥 Inputs |
| 62 | +| **Name** | **Required** | **Description** | **Default** | |
| 63 | +|--------------------------|--------------|--------------------------------------------------------------------------------------|-------------| |
| 64 | +| `aws_access_key_id` | ❌ No | AWS access key ID (optional if using OIDC) | - | |
| 65 | +| `aws_secret_access_key` | ❌ No | AWS secret access key (optional if using OIDC) | - | |
| 66 | +| `aws_region` | ✅ Yes | AWS region | - | |
| 67 | +| `aws_account_id` | ✅ Yes | AWS account ID (12 digits) | - | |
| 68 | +| `role_to_assume` | ❌ No | AWS IAM role ARN to assume (for OIDC authentication) | - | |
| 69 | +| `function_name` | ✅ Yes | Full Lambda function name | - | |
| 70 | +| `image_uri` | ❌ No | Full ECR image URI (overrides `repository`/`image_tag` when provided) | - | |
| 71 | +| `repository` | ❌ No | ECR repository name (used if `image_uri` not provided) | - | |
| 72 | +| `image_tag` | ❌ No | ECR image tag (used with `repository`) | `latest` | |
| 73 | +| `wait_for_update` | ❌ No | Wait for function update to complete (`true`/`false`) | `true` | |
| 74 | + |
| 75 | +## 📤 Outputs |
| 76 | +| **Name** | **Description** | |
| 77 | +|------------------|-----------------------------------------| |
| 78 | +| `function_arn` | Lambda function ARN | |
| 79 | +| `last_modified` | Function last modified timestamp | |
| 80 | +| `code_sha256` | Lambda code SHA256 | |
| 81 | + |
| 82 | +## 📋 Examples |
| 83 | +[View example →](./examples/base.yml) |
0 commit comments