Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aws-samples/aws-lambda-layer-kubectl
AWS Lambda Layer with kubectl and Helm
https://github.com/aws-samples/aws-lambda-layer-kubectl
Last synced: 12 days ago
JSON representation
AWS Lambda Layer with kubectl and Helm
- Host: GitHub
- URL: https://github.com/aws-samples/aws-lambda-layer-kubectl
- Owner: aws-samples
- License: apache-2.0
- Archived: true
- Created: 2019-04-16T15:47:49.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-04-06T18:44:15.000Z (over 2 years ago)
- Last Synced: 2024-08-02T06:14:08.828Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 11.8 MB
- Stars: 144
- Watchers: 6
- Forks: 51
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-layers - `aws-samples/aws-lambda-layer-kubectl`
README
[![build](https://github.com/aws-samples/aws-lambda-layer-kubectl/actions/workflows/build.yml/badge.svg)](https://github.com/aws-samples/aws-lambda-layer-kubectl/actions/workflows/build.yml)
# lambda-layer-kubectl
AWS CDK(Cloud Development Kit) comes with [lambda-layer-kubectl](https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/lambda-layer-kubectl) which allows you to build your private AWS Lambda layer with **kubectl** executable. Ths repository demonstrates how to create your own AWS Lambda layer with kubectl in AWS CDK.
## Basic Usage
```ts
import { App, CfnOutput, Construct, Stack, StackProps } from '@aws-cdk/core';
import * as layer from '@aws-cdk/lambda-layer-kubectl';export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);const kubectlLayer = new layer.KubectlLayer(this, 'KubectlLayer');
new CfnOutput(this, 'LayerVersionArn', { value: kubectlLayer.layerVersionArn })}
}const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};const app = new App();
new MyStack(app, 'kubectl-layer-stack', { env: devEnv });
app.synth();
```After deployment, the AWS Lambda layer version ARN will be returned and you can use this ARN in your Lambda functions in the same AWS region.
```
Outputs:
kubectl-layer-stack.LayerVersionArn = arn:aws:lambda:us-east-1:123456789012:layer:KubectlLayer600207B5:1
```## Customize your layer
The [kubectlLayer](https://github.com/aws/aws-cdk/blob/6e2a3e0f855221df98f78f6465586d5524f5c7d5/packages/%40aws-cdk/lambda-layer-kubectl/lib/kubectl-layer.ts#L10-L20) from AWS CDK upstream does not allow you to pass custom Dockerfile(see the [build-in Dockerfile](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/lambda-layer-kubectl/layer/Dockerfile)). To customize the layer, we simply create our own `KubectlLayer` construct class in our CDK application with our custom `Dockerfile`.
```sh
cd src/custom-layer
# edit and customize the Dockerfile under the `custom-layer` directory
# generate the layer.zip from Dockerfile
bash build.sh
```Now prepare your custom `KubectlLayer` construct class and run `cdk deploy` to generate your own layer.
```ts
import { App, CfnOutput, Construct, Stack, StackProps } from '@aws-cdk/core';
import * as customlayer from './custom-layer/custom-layer'export class CustomLayderStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);const kubectlLayer = new customlayer.KubectlLayer(this, 'CustomKubectlLayer');
new CfnOutput(this, 'LayerVersionArn', { value: kubectlLayer.layerVersionArn })}
}const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};const app = new App();
new CustomLayderStack(app, 'custom-kubectl-layer-stack', { env: devEnv });
app.synth();
```## License Summary
This sample code is made available under the MIT-0 license. See the LICENSE file.