Last active
November 20, 2022 02:10
-
-
Save sscovil/d4e0ef2c928e51ad138d1d33b5203628 to your computer and use it in GitHub Desktop.
Example usage of HttpLambda CDKTF construct (https://gist.github.com/sscovil/537de0e58aef59a60d49fddc4662ed81)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from cdktf import App, TerraformStack, TerraformOutput | |
from cdktf_cdktf_provider_aws.lambda_function_url import LambdaFunctionUrlCors | |
from cdktf_cdktf_provider_aws.provider import AwsProvider | |
from constructs import Construct | |
from http_lambda import HttpLambda | |
class ExampleStack(TerraformStack): | |
def __init__(self, scope: Construct, ns: str): | |
super().__init__(scope, ns) | |
AwsProvider(self, "aws", region="us-east-1") | |
http_lambda = HttpLambda( | |
self, | |
ns, | |
cors=LambdaFunctionUrlCors( | |
allow_headers=["Content-Type"], | |
allow_methods=["OPTIONS", "POST", "GET"], | |
allow_origins=["https://www.example.com"], | |
), | |
env={"ENVIRONMENT": "staging"}, | |
function_name="my-lambda-function", | |
handler="index.lambda_handler", | |
iam_role_name="my-lambda-execution-role", | |
path="lib/assets/example", | |
runtime="python3.9", | |
) | |
TerraformOutput(self, "iam_role_name", value=http_lambda.iam_role_name) | |
TerraformOutput(self, "function_name", value=http_lambda.function_name) | |
TerraformOutput(self, "function_url", value=http_lambda.function_url) | |
app = App() | |
ExampleStack(app, "example") | |
app.synth() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment