Class AssetCode

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.lambda.Code
software.amazon.awscdk.services.lambda.AssetCode
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.101.0 (build b95fe5d)", date="2024-08-15T01:32:50.284Z") @Stability(Stable) public class AssetCode extends Code
Lambda code from a local directory.

Example:

 // Lambda function containing logic that evaluates compliance with the rule.
 Function evalComplianceFn = Function.Builder.create(this, "CustomFunction")
         .code(AssetCode.fromInline("exports.handler = (event) => console.log(event);"))
         .handler("index.handler")
         .runtime(Runtime.NODEJS_18_X)
         .build();
 // A custom rule that runs on configuration changes of EC2 instances
 CustomRule customRule = CustomRule.Builder.create(this, "Custom")
         .configurationChanges(true)
         .lambdaFunction(evalComplianceFn)
         .ruleScope(RuleScope.fromResource(ResourceType.EC2_INSTANCE))
         .build();
 // A rule to detect stack drifts
 CloudFormationStackDriftDetectionCheck driftRule = new CloudFormationStackDriftDetectionCheck(this, "Drift");
 // Topic to which compliance notification events will be published
 Topic complianceTopic = new Topic(this, "ComplianceTopic");
 // Send notification on compliance change events
 driftRule.onComplianceChange("ComplianceChange", OnEventOptions.builder()
         .target(new SnsTopic(complianceTopic))
         .build());
 
  • Constructor Details

    • AssetCode

      protected AssetCode(software.amazon.jsii.JsiiObjectRef objRef)
    • AssetCode

      protected AssetCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • AssetCode

      @Stability(Stable) public AssetCode(@NotNull String path, @Nullable AssetOptions options)
      Parameters:
      path - The path to the asset file or directory. This parameter is required.
      options -
    • AssetCode

      @Stability(Stable) public AssetCode(@NotNull String path)
      Parameters:
      path - The path to the asset file or directory. This parameter is required.
  • Method Details

    • bind

      @Stability(Stable) @NotNull public CodeConfig bind(@NotNull software.constructs.Construct scope)
      Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.

      Specified by:
      bind in class Code
      Parameters:
      scope - This parameter is required.
    • bindToResource

      @Stability(Stable) public void bindToResource(@NotNull CfnResource resource, @Nullable ResourceBindOptions 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.

      Overrides:
      bindToResource in class Code
      Parameters:
      resource - This parameter is required.
      options -
    • bindToResource

      @Stability(Stable) public void bindToResource(@NotNull CfnResource resource)
      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.

      Overrides:
      bindToResource in class Code
      Parameters:
      resource - This parameter is required.
    • getIsInline

      @Stability(Stable) @NotNull public Boolean getIsInline()
      Determines whether this Code is inline code or not.
    • getPath

      @Stability(Stable) @NotNull public String getPath()
      The path to the asset file or directory.