aws-cdk-lib.aws_lambda.AssetCode

class AssetCode

LanguageType name
.NETAmazon.CDK.AWS.Lambda.AssetCode
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslambda#AssetCode
Javasoftware.amazon.awscdk.services.lambda.AssetCode
Pythonaws_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

NameTypeDescription
isInlinebooleanDetermines whether this Code is inline code or not.
pathstringThe 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

NameDescription
bind(scope)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?)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

  • CodeConfig

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 ResourceBindOptions

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.