class AssetCode
| Language | Type name | 
|---|---|
  .NET | Amazon.CDK.AWS.Lambda.AssetCode | 
  Go | github.com/aws/aws-cdk-go/awscdk/v2/awslambda#AssetCode | 
  Java | software.amazon.awscdk.services.lambda.AssetCode | 
  Python | aws_cdk.aws_lambda.AssetCode | 
  TypeScript (source) | aws-cdk-lib » aws_lambda » AssetCode | 
Extends
Code
Lambda code from a local directory.
Example
// Lambda function containing logic that evaluates compliance with the rule.
const evalComplianceFn = new lambda.Function(this, 'CustomFunction', {
  code: lambda.AssetCode.fromInline('exports.handler = (event) => console.log(event);'),
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_18_X,
});
// A custom rule that runs on configuration changes of EC2 instances
const customRule = new config.CustomRule(this, 'Custom', {
  configurationChanges: true,
  lambdaFunction: evalComplianceFn,
  ruleScope: config.RuleScope.fromResource(config.ResourceType.EC2_INSTANCE),
});
// A rule to detect stack drifts
const driftRule = new config.CloudFormationStackDriftDetectionCheck(this, 'Drift');
// Topic to which compliance notification events will be published
const complianceTopic = new sns.Topic(this, 'ComplianceTopic');
// Send notification on compliance change events
driftRule.onComplianceChange('ComplianceChange', {
  target: new targets.SnsTopic(complianceTopic),
});
Initializer
new AssetCode(path: string, options?: AssetOptions)
Parameters
- path 
string— The path to the asset file or directory. - options 
AssetOptions  
Properties
| Name | Type | Description | 
|---|---|---|
| is | boolean | Determines whether this Code is inline code or not. | 
| path | string | The path to the asset file or directory. | 
isInline
Type:
boolean
Determines whether this Code is inline code or not.
path
Type:
string
The path to the asset file or directory.
Methods
| Name | Description | 
|---|---|
| bind(scope) | Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun. | 
| bind | Called after the CFN function resource has been created to allow the code class to bind to it. | 
bind(scope)
public bind(scope: Construct): CodeConfig
Parameters
- scope 
Construct 
Returns
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
bindToResource(resource, options?)  
public bindToResource(resource: CfnResource, options?: ResourceBindOptions): void
Parameters
- resource 
CfnResource  - options 
ResourceBind Options  
Called after the CFN function resource has been created to allow the code class to bind to it.
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.

 .NET
 Go
 Java
 Python
 TypeScript (