@Generated(value="jsii-pacmak/1.74.0 (build 6d08790)", date="2023-05-10T17:05:56.372Z") @Stability(value=Stable) public class AssetCode extends Code
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());
| Modifier | Constructor and Description |
|---|---|
protected |
AssetCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
AssetCode(software.amazon.jsii.JsiiObjectRef objRef) |
|
AssetCode(String path) |
|
AssetCode(String path,
AssetOptions options) |
| Modifier and Type | Method and Description |
|---|---|
CodeConfig |
bind(Construct scope)
Called 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.
|
Boolean |
getIsInline()
Determines whether this Code is inline code or not.
|
String |
getPath()
The path to the asset file or directory.
|
asset, bucket, bucket, cfnParameters, cfnParameters, fromAsset, fromAsset, fromAssetImage, fromAssetImage, fromBucket, fromBucket, fromCfnParameters, fromCfnParameters, fromDockerBuild, fromDockerBuild, fromEcrImage, fromEcrImage, fromInline, inlinejsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetprotected AssetCode(software.amazon.jsii.JsiiObjectRef objRef)
protected AssetCode(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
@Stability(value=Stable)
public AssetCode(@NotNull
String path,
@Nullable
AssetOptions options)
path - The path to the asset file or directory. This parameter is required.options - @Stability(value=Stable)
public AssetCode(@NotNull
String path)
path - The path to the asset file or directory. This parameter is required.@Stability(value=Stable) @NotNull public CodeConfig bind(@NotNull Construct scope)
@Stability(value=Stable)
public void bindToResource(@NotNull
CfnResource resource,
@Nullable
ResourceBindOptions options)
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
bindToResource in class Coderesource - This parameter is required.options - @Stability(value=Stable)
public void bindToResource(@NotNull
CfnResource resource)
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.
bindToResource in class Coderesource - This parameter is required.@Stability(value=Stable) @NotNull public Boolean getIsInline()
getIsInline in class Code@Stability(value=Stable) @NotNull public String getPath()
Copyright © 2023. All rights reserved.