Class AssetCode
Lambda code from a local directory.
Inherited Members
Namespace: Amazon.CDK.AWS.Lambda
Assembly: Amazon.CDK.AWS.Lambda.dll
Syntax (csharp)
public class AssetCode : Code
Syntax (vb)
Public Class AssetCode
Inherits Code
Remarks
ExampleMetadata: lit=test/authorizers/integ.token-authorizer.lit.ts infused
Examples
using Path;
using Amazon.CDK.AWS.Lambda;
using Amazon.CDK;
using Amazon.CDK.AWS.APIGateway;
/*
* 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
*/
var app = new App();
var stack = new Stack(app, "TokenAuthorizerInteg");
var authorizerFn = new Function(stack, "MyAuthorizerFunction", new FunctionProps {
Runtime = Runtime.NODEJS_14_X,
Handler = "index.handler",
Code = AssetCode.FromAsset(Join(__dirname, "integ.token-authorizer.handler"))
});
var restapi = new RestApi(stack, "MyRestApi");
var authorizer = new TokenAuthorizer(stack, "MyAuthorizer", new TokenAuthorizerProps {
Handler = authorizerFn
});
restapi.Root.AddMethod("ANY", new MockIntegration(new IntegrationOptions {
IntegrationResponses = new [] { new IntegrationResponse { StatusCode = "200" } },
PassthroughBehavior = PassthroughBehavior.NEVER,
RequestTemplates = new Dictionary<string, string> {
{ "application/json", "{ \"statusCode\": 200 }" }
}
}), new MethodOptions {
MethodResponses = new [] { new MethodResponse { StatusCode = "200" } },
Authorizer = authorizer
});
Synopsis
Constructors
AssetCode(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
AssetCode(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
AssetCode(String, IAssetOptions) |
Properties
IsInline | Determines whether this Code is inline code or not. |
Path | The path to the asset file or directory. |
Methods
Bind(Construct) | Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun. |
BindToResource(CfnResource, IResourceBindOptions) | Called after the CFN function resource has been created to allow the code class to bind to it. |
Constructors
AssetCode(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected AssetCode(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
AssetCode(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected AssetCode(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
AssetCode(String, IAssetOptions)
public AssetCode(string path, IAssetOptions options = null)
Parameters
- path System.String
The path to the asset file or directory.
- options IAssetOptions
The path to the asset file or directory.
Properties
IsInline
Determines whether this Code is inline code or not.
public override bool IsInline { get; }
Property Value
System.Boolean
Overrides
Path
The path to the asset file or directory.
public virtual string Path { get; }
Property Value
System.String
Methods
Bind(Construct)
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
public override ICodeConfig Bind(Construct scope)
Parameters
- scope Construct
Returns
Overrides
BindToResource(CfnResource, IResourceBindOptions)
Called after the CFN function resource has been created to allow the code class to bind to it.
public override void BindToResource(CfnResource resource, IResourceBindOptions options = null)
Parameters
- resource CfnResource
- options IResourceBindOptions
Overrides
Remarks
Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.