{"id":37058395,"url":"https://github.com/cargo-lambda/cargo-lambda-cdk","last_synced_at":"2026-01-14T06:35:51.827Z","repository":{"id":64934936,"uuid":"578020363","full_name":"cargo-lambda/cargo-lambda-cdk","owner":"cargo-lambda","description":"CDK Construct to build Rust functions with Cargo Lambda","archived":false,"fork":false,"pushed_at":"2025-12-08T22:13:58.000Z","size":53851,"stargazers_count":136,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-01-04T14:16:11.395Z","etag":null,"topics":["aws","aws-cdk","aws-lambda","rust"],"latest_commit_sha":null,"homepage":"https://www.cargo-lambda.info","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cargo-lambda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["calavera"]}},"created_at":"2022-12-14T04:06:33.000Z","updated_at":"2025-12-10T08:02:22.000Z","dependencies_parsed_at":"2024-06-19T16:03:14.381Z","dependency_job_id":"bafd021a-c61e-4258-9961-a1677055b27a","html_url":"https://github.com/cargo-lambda/cargo-lambda-cdk","commit_stats":{"total_commits":79,"total_committers":10,"mean_commits":7.9,"dds":0.379746835443038,"last_synced_commit":"91d5dd67088c724d88fd9eb86b1edff2abcc79d6"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"purl":"pkg:github/cargo-lambda/cargo-lambda-cdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cargo-lambda%2Fcargo-lambda-cdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cargo-lambda%2Fcargo-lambda-cdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cargo-lambda%2Fcargo-lambda-cdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cargo-lambda%2Fcargo-lambda-cdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cargo-lambda","download_url":"https://codeload.github.com/cargo-lambda/cargo-lambda-cdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cargo-lambda%2Fcargo-lambda-cdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28412211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cdk","aws-lambda","rust"],"created_at":"2026-01-14T06:35:51.152Z","updated_at":"2026-01-14T06:35:51.809Z","avatar_url":"https://github.com/cargo-lambda.png","language":"Go","funding_links":["https://github.com/sponsors/calavera"],"categories":[],"sub_categories":[],"readme":"# Cargo Lambda CDK construct\n\nThis library provides constructs for Rust Lambda functions built with Cargo Lambda\n\nTo use this module you will either need to have [Cargo Lambda installed](https://www.cargo-lambda.info/guide/installation.html) (`0.12.0` or later), or `Docker` installed.\nSee [Local Bundling](#local-bundling)/[Docker Bundling](#docker-bundling) for more information.\n\n## Installation\n\n### JavaScript / TypeScript\n\nYou can add [the npm package](https://npmjs.com/package/cargo-lambda-cdk) to your program as follows,\n\n```bash\nnpm i cargo-lambda-cdk\n```\n\nOr using any other compatible package manager\n\n### Go\n\nAdd the following to your imports,\n\n```plain\ngithub.com/cargo-lambda/cargo-lambda-cdk/cargolambdacdk\n```\n\n### Python\n\nYou can add [the Python package](https://pypi.org/project/cargo-lambda-cdk) using `pip`, or any other package manager compatible with PyPI,\n\n```bash\npip install cargo-lambda-cdk\n```\n\n## Rust Function\n\nDefine a `RustFunction`:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(stack, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n});\n```\n\nThe layout for this Rust project could look like this:\n\n```bash\nlambda-project\n├── Cargo.toml\n└── src\n    └── main.rs\n```\n\n### Runtime\n\nThe `RustFunction` uses the `provided.al2023` runtime. If you want to change it, you can use the property `runtime`. The only other valid option is `provided.al2`:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(stack, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  runtime: 'provided.al2',\n});\n```\n\n## Rust Extension\n\nDefine a `RustExtension` that get's deployed as a layer to use it with any other function later.\n\n```ts\nimport { RustExtension, RustFunction } from 'cargo-lambda-cdk';\nimport { Architecture } from 'aws-cdk-lib/aws-lambda';\n\nconst extensionLayer = new RustExtension(this, 'Rust extension', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  architecture: Architecture.ARM_64,\n});\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  layers: [\n    extensionLayer\n  ],\n});\n```\n\n## Remote Git sources\n\nBoth `RustFunction` and `RustExtension` support cloning a git repository to get the source code for the function or extension.\nTo download the source code from a remote git repository, specify the `gitRemote`. This option can be a valid git remote url, such as `https://github.com/your_user/your_repo`, or a valid ssh url, such as `git@github.com:your_user/your_repo.git`.\n\nBy default, the latest commit from the `HEAD` branch will be downloaded. To download a different git reference, specify the `gitReference` option. This can be a branch name, tag, or commit hash.\n\nIf you want to always clone the repository even if it has already been cloned to the temporary directory, set the `gitForceClone` option to `true`.\n\nIf you specify a `manifestPath`, it will be relative to the root of the git repository once it has been cloned.\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(stack, 'Rust function', {\n  gitRemote: 'https://github.com/your_user/your_repo',\n  gitReference: 'branch',\n  gitForceClone: true,\n});\n```\n\n## Bundling\n\nBundling is the process by which `cargo lambda` gets called to build, package, and deliver the Rust\nbinary for CDK. This construct provides two methods of bundling: \n - Local bundling where the locally installed cargo lambda tool will run\n - Docker bundling where a Dockerfile can be specified to build an image\n\n### Local Bundling\n\nIf `Cargo Lambda` is installed locally then it will be used to bundle your code in your environment. Otherwise, bundling will happen in a Lambda compatible Docker container with the Docker platform based on the target architecture of the Lambda function.\n\n### Environment\n\nUse the `environment` prop to define additional environment variables when Cargo Lambda runs:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    environment: {\n      HELLO: 'WORLD',\n    },\n  },\n});\n```\n\n### Cargo Build profiles\n\nUse the `profile` option if you want to build with a different Cargo profile that's not `release`:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    profile: 'dev'\n  },\n});\n```\n\n### Cargo Lambda Build flags\n\nUse the `cargoLambdaFlags` option to add additional flags to the `cargo lambda build` command that's executed to bundle your function. You don't need to use this flag to set options like the target architecture or the binary to compile, since the construct infers those from other props.\n\nIf these flags include a `--target` flag, it will override the `architecture` option. If these flags include a `--release` or `--profile` flag, it will override the release or any other profile specified.\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    cargoLambdaFlags: [\n      '--target',\n      'x86_64-unknown-linux-musl',\n      '--debug',\n      '--disable-optimizations',\n    ],\n  },\n});\n```\n\n### Docker\n\nTo force bundling in a docker container even if `Cargo Lambda` is available in your environment, set the `forcedDockerBundling` prop to `true`. This is useful if you want to make sure that your function is built in a consistent Lambda compatible environment.\n\nBy default, these constructs use [ghcr.io/cargo-lambda/cargo-lambda](https://github.com/cargo-lambda/cargo-lambda/pkgs/container/cargo-lambda) as the image to build with. Use the `bundling.dockerImage` prop to use a custom bundling image:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    dockerImage: DockerImage.fromBuild('/path/to/Dockerfile'),\n  },\n});\n```\n\nAdditional docker options such as the user, file access, working directory or volumes can be configured by using the `bundling.dockerOptions` prop:\n\n```ts\nimport * as cdk from 'aws-cdk-lib';\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    dockerOptions: {\n      bundlingFileAccess: cdk.BundlingFileAccess.VOLUME_COPY,\n    },\n  },\n});\n```\n\nThis property mirrors values from the `cdk.BundlingOptions` and is passed into `Code.fromAsset`.\n\nIf you want to use a custom Docker image, you can use the `bundling.dockerImage` prop:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    dockerImage: DockerImage.fromRegistry('your_docker_image'),\n  },\n});\n```\n\nIf you want to mount additional volumes to the Docker container, you can use the `dockerOptions.volumes` prop. This is useful if you want to mount Cargo's cache directory to speed up the build process. The `CARGO_HOME` in the default image is `/usr/local/cargo`.\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\nimport { homedir } from 'os';\nimport { join } from 'path';\n\nconst cargoHome = process.env.CARGO_HOME || join(homedir(), '.cargo');\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    dockerOptions: {\n      volumes: [{\n        hostPath: join(cargoHome, 'registry'),\n        containerPath: '/usr/local/cargo/registry',\n      },\n      {\n        hostPath: join(cargoHome, 'git'),\n        containerPath: '/usr/local/cargo/git',\n      }],\n    },\n  },\n});\n```\n\n### Command hooks\n\nIt is  possible to run additional commands by specifying the `commandHooks` prop:\n\n```ts\nimport { RustFunction } from 'cargo-lambda-cdk';\n\nnew RustFunction(this, 'Rust function', {\n  manifestPath: 'path/to/package/directory/with/Cargo.toml',\n  bundling: {\n    commandHooks: {\n      // run tests\n      beforeBundling(inputDir: string, _outputDir: string): string[] {\n        return ['cargo test'];\n      },\n    },\n  },\n});\n```\n\nThe following hooks are available:\n\n* `beforeBundling`: runs before all bundling commands\n* `afterBundling`: runs after all bundling commands\n\nThey all receive the directory containing the `Cargo.toml` file (`inputDir`) and the\ndirectory where the bundled asset will be output (`outputDir`). They must return\nan array of commands to run. Commands are chained with `\u0026\u0026`.\n\nThe commands will run in the environment in which bundling occurs: inside the\ncontainer for Docker bundling or on the host OS for local bundling.\n\n## Additional considerations\n\nDepending on how you structure your Rust application, you may want to change the `assetHashType` parameter.\nBy default this parameter is set to `AssetHashType.OUTPUT` which means that the CDK will calculate the asset hash\n(and determine whether or not your code has changed) based on the Rust executable that is created.\n\nIf you specify `AssetHashType.SOURCE`, the CDK will calculate the asset hash by looking at the folder\nthat contains your `Cargo.toml` file. If you are deploying a single Lambda function, or you want to redeploy\nall of your functions if anything changes, then `AssetHashType.SOURCE` will probaby work.\n\n## LICENSE\n\nThis software is released under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcargo-lambda%2Fcargo-lambda-cdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcargo-lambda%2Fcargo-lambda-cdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcargo-lambda%2Fcargo-lambda-cdk/lists"}