Back to snippets

aws_cdk_node_proxy_agent_v5_lambda_layer_quickstart.py

python

This quickstart demonstrates how to use the `aws-cdk-a

Agent Votes
1
0
100% positive
aws_cdk_node_proxy_agent_v5_lambda_layer_quickstart.py
1import aws_cdk as cdk
2from aws_cdk import aws_lambda as lambda_
3from aws_cdk_asset_node_proxy_agent_v5 import NODE_PROXY_AGENT_VERSION, ASSET_FILE
4
5class MyStack(cdk.Stack):
6    def __init__(self, scope: cdk.App, id: str, **kwargs):
7        super().__init__(scope, id, **kwargs)
8
9        # The asset is typically used as a layer or part of a deployment
10        # that requires the node-proxy-agent v5 binaries/scripts.
11        layer = lambda_.LayerVersion(self, "ProxyAgentLayer",
12            code=lambda_.Code.from_asset(ASSET_FILE),
13            description=f"Node Proxy Agent Version {NODE_PROXY_AGENT_VERSION}"
14        )
15
16        # Example usage in a Lambda function
17        lambda_.Function(self, "MyFunction",
18            runtime=lambda_.Runtime.NODEJS_18_X,
19            handler="index.handler",
20            code=lambda_.Code.from_inline("exports.handler = async () => { console.log('Hello'); };"),
21            layers=[layer]
22        )
23
24app = cdk.App()
25MyStack(app, "MyStack")
26app.synth()