Registry / aws / aws-cdk-asset-awscli-v1

aws-cdk-asset-awscli-v1

JSON →
library2.2.274pypypiunverified

The `aws-cdk-asset-awscli-v1` library provides the AWS CLI (version 1) as a Lambda Layer asset for use within AWS CDK applications. It allows Lambda functions to execute AWS CLI commands directly. This package is maintained by cdklabs and receives updates in sync with the broader AWS CDK ecosystem.

awsdevops
pip install aws-cdk-asset-awscli-v1 aws-cdk-lib
Install & Compatibility
Where this runs
tested against v2.2.282 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
4/6 runs
4/6 runs
py 3.11
4/6 runs
4/6 runs
py 3.12
4/6 runs
4/6 runs
py 3.13
4/6 runs
4/6 runs
py 3.9
4/6 runs
4/6 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AwsCliLayer
from aws_cdk_asset_awscli_v1 import AwsCliLayer
from aws_cdk.aws_lambda import AwsCliLayer
The `AwsCliLayer` from this package is a separate asset construct, not directly part of `aws-cdk-lib`'s core `aws_lambda` module.

This quickstart demonstrates how to create an `AwsCliLayer` and attach it to a Lambda function. The Lambda's code then executes a simple AWS CLI command (`aws s3 ls`). Remember to grant the Lambda's execution role the necessary IAM permissions for any AWS CLI commands it will run.

import os from aws_cdk import ( App, Stack, aws_lambda as lambda_, ) from aws_cdk_asset_awscli_v1 import AwsCliLayer class MyAwsCliStack(Stack): def __init__(self, scope: App, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) # Create the AWS CLI v1 Lambda Layer aws_cli_layer = AwsCliLayer(self, "AwsCliV1Layer") # Define a Lambda function that uses the layer lambda_function = lambda_.Function( self, "MyLambdaWithAwsCli", runtime=lambda_.Runtime.PYTHON_3_9, # Ensure compatibility with asset's Python requirement handler="index.handler", code=lambda_.Code.from_inline( """ import json import subprocess def handler(event, context): try: # Example: run 'aws s3 ls' to list S3 buckets # The Lambda's IAM role must have s3:ListBucket permissions. result = subprocess.run(['aws', 's3', 'ls'], capture_output=True, text=True, check=True) return { 'statusCode': 200, 'body': json.dumps({'message': 'AWS CLI executed successfully', 'output': result.stdout}) } except subprocess.CalledProcessError as e: return { 'statusCode': 500, 'body': json.dumps({'error': f"AWS CLI error: {e.stderr}"}) } except Exception as e: return { 'statusCode': 500, 'body': json.dumps({'error': str(e)}) } """ ), layers=[aws_cli_layer], # Add IAM permissions required for CLI commands, e.g., s3:ListBucket for 'aws s3 ls' # For a production setup, consider defining a more granular policy. # lambda_function.add_to_role_policy(iam.PolicyStatement(actions=["s3:ListBucket"], resources=["arn:aws:s3:::*"])) ) app = App() MyAwsCliStack(app, "MyAwsCliStack") app.synth()
Debug
Known issues
gotchaThis package specifically provides AWS CLI v1. If you require AWS CLI v2, you MUST use the `aws-cdk-asset-awscli-v2` package instead. Mixing versions or mistakenly assuming v2 can lead to unexpected behavior or missing features.
fix
Verify the required AWS CLI version. If v2 is needed, install `aws-cdk-asset-awscli-v2` and import `AwsCliLayer` from there.
affects: All versions of `aws-cdk-asset-awscli-v1`.
gotchaThe AWS CLI layer is substantial in size (around 50MB unzipped). This can contribute to increased Lambda cold start times and potentially push your deployment package size close to Lambda limits. Only include it if truly necessary.
fix
Evaluate if a custom layer with only the specific tools or subset of AWS CLI commands you need could be more efficient. Benchmark cold start times in your application.
affects: All versions.
gotchaThis asset package has specific Python runtime requirements (e.g., `~=3.9` as per PyPI). Using a Lambda function with an incompatible Python runtime (e.g., Python 3.7 or Python 3.12 if not supported) may lead to runtime errors when the CLI attempts to execute.
fix
Ensure your Lambda function's runtime (`lambda_.Runtime.PYTHON_X_Y`) matches the `requires_python` specification of the installed `aws-cdk-asset-awscli-v1` version.
affects: All versions.
breakingThis AWS CDK asset package relies on `jsii` which requires Node.js to be installed and available in the environment's PATH. If Node.js is not present, the library will fail to load with a `FileNotFoundError: [Errno 2] No such file or directory: 'node'`.
fix
Ensure Node.js is installed and accessible in the execution environment (e.g., in your Dockerfile, install `nodejs` and `npm`).
affects: All versions.
breakingAWS CDK and its `jsii` runtime fundamentally depend on Node.js being installed and discoverable in the system's PATH. The error `FileNotFoundError: [Errno 2] No such file or directory: 'node'` indicates that the 'node' executable could not be found, preventing the AWS CDK library from initializing.
fix
Ensure Node.js is installed in your environment and accessible via the system's PATH. For Alpine-based Docker images, you can typically install it using `apk add nodejs`. Check AWS CDK documentation for recommended Node.js versions.
affects: All versions of `aws-cdk` and `aws-cdk-asset-awscli-v1`.
Upgrade
Version history
2.2.283latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
59 hits · last 30 days
node
10
mj12bot
3
ahrefsbot
2
seranking-bot
2
Amazon
1
amazonbot
1
Resources