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.84.0 (build 5404dcf)",
date="2023-06-19T16:30:40.552Z")
@Stability(Stable)
public class AssetCode
extends Code
Lambda code from a local directory.
Example:
import path.*; import software.amazon.awscdk.services.lambda.*; import software.amazon.awscdk.core.App; import software.amazon.awscdk.core.Stack; import software.amazon.awscdk.services.apigateway.MockIntegration; import software.amazon.awscdk.services.apigateway.PassthroughBehavior; import software.amazon.awscdk.services.apigateway.RestApi; import software.amazon.awscdk.services.apigateway.TokenAuthorizer; /* * Stack verification steps: * * `curl -s -o /dev/null -w "%{http_code}" <url>` should return 401 * * `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: deny' <url>` should return 403 * * `curl -s -o /dev/null -w "%{http_code}" -H 'Authorization: allow' <url>` should return 200 */ App app = new App(); Stack stack = new Stack(app, "TokenAuthorizerInteg"); Function authorizerFn = Function.Builder.create(stack, "MyAuthorizerFunction") .runtime(Runtime.NODEJS_14_X) .handler("index.handler") .code(AssetCode.fromAsset(join(__dirname, "integ.token-authorizer.handler"))) .build(); RestApi restapi = new RestApi(stack, "MyRestApi"); TokenAuthorizer authorizer = TokenAuthorizer.Builder.create(stack, "MyAuthorizer") .handler(authorizerFn) .build(); restapi.root.addMethod("ANY", MockIntegration.Builder.create() .integrationResponses(List.of(IntegrationResponse.builder().statusCode("200").build())) .passthroughBehavior(PassthroughBehavior.NEVER) .requestTemplates(Map.of( "application/json", "{ \"statusCode\": 200 }")) .build(), MethodOptions.builder() .methodResponses(List.of(MethodResponse.builder().statusCode("200").build())) .authorizer(authorizer) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCalled when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.void
bindToResource
(CfnResource resource) Called after the CFN function resource has been created to allow the code class to bind to it.void
bindToResource
(CfnResource resource, ResourceBindOptions options) Called after the CFN function resource has been created to allow the code class to bind to it.Determines whether this Code is inline code or not.getPath()
The path to the asset file or directory.Methods inherited from class software.amazon.awscdk.services.lambda.Code
asset, bucket, bucket, cfnParameters, cfnParameters, fromAsset, fromAsset, fromAssetImage, fromAssetImage, fromBucket, fromBucket, fromCfnParameters, fromCfnParameters, fromDockerBuild, fromDockerBuild, fromEcrImage, fromEcrImage, fromInline, inline
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
AssetCode
protected AssetCode(software.amazon.jsii.JsiiObjectRef objRef) -
AssetCode
protected AssetCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
AssetCode
- Parameters:
path
- The path to the asset file or directory. This parameter is required.options
-
-
AssetCode
- Parameters:
path
- The path to the asset file or directory. This parameter is required.
-
-
Method Details
-
bind
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun. -
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 classCode
- Parameters:
resource
- This parameter is required.options
-
-
bindToResource
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 classCode
- Parameters:
resource
- This parameter is required.
-
getIsInline
Determines whether this Code is inline code or not.- Specified by:
getIsInline
in classCode
-
getPath
The path to the asset file or directory.
-