Estoy usando Terraform CDK para implementar una función lambda y estoy tratando de configurar un disparador usando notificaciones s3. Soy algo nuevo en CDK, así que no estoy seguro de dónde pueden estar yendo mal las cosas aquí.
Al leer este ejemplo y también en base a lo que se hace con el CDK normal, pensé que para acceder a la función arn (para agregarla a la configuración de notificación del depósito), sería my_function.arn , pero muestra la siguiente cadena {TfToken[TOKEN.XXX]} .
Me parece que podría obtener el arn en algún lugar con este valor, pero no pude averiguar dónde.
Pensé en dividirlo en dos pilas, pero necesitaba que tanto lambda como su activador de notificación se implementaran juntos.
el codigo es
#!/usr/bin/env python from constructs import Construct from cdktf import App, TerraformStack, TerraformOutput from imports.aws import AwsProvider from imports.aws.lambdafunction import LambdaFunction from imports.aws.s3 import S3BucketNotification, S3BucketNotificationLambdaFunction import os class My_Stack(TerraformStack): def __init__(self, scope: Construct, ns: str): super().__init__(scope, ns) AwsProvider(self, 'Aws', region='my-region') my_lambda_function = LambdaFunction( self, id='id', function_name='cdk-deployment-test', role='my-role', memory_size=128, runtime='python3.8', timeout=900, handler="lambda_handler", filename=os.path.join(os.getcwd(), 'deployment_package/package.zip') ) function_to_be_triggered = S3BucketNotificationLambdaFunction( lambda_function_arn= my_lambda_function.arn, events = ["s3:ObjectCreate:*"], filter_prefix = "path" ) payment_recognition_input = S3BucketNotification( self, id='s3-bucket-notification', bucket = 'my-bucket', lambda_function=[function_to_be_triggered] ) app = App() My_Stack(app, "cdktf-poc") app.synth()Esta es la forma correcta de hacer referencia a la propiedad ARN del recurso terraform, los {TfToken[TOKEN.XXX]} se resuelven en la sintaxis del lenguaje Terraform en la salida del sintetizador. Consulte la documentación de CDK para Terraform aquí que analiza los tokens:
Por ejemplo, este código CDKTF:
const vpc = new Vpc(this, "my-vpc", { name: vpcName, }); new Eks(this, "EksModule", { clusterName: "my-kubernetes-cluster", vpcId: vpc.vpcIdOutput, });finalmente genera (usando token) esta terraformación:
{ "module": { "helloterraEksModule5DDB67AE": { "cluster_name": "my-kubernetes-cluster", "vpc_id": "${module.helloterraMyVpc62D94C17.vpc_id}" } } }De modo que esa referencia y el enlace de dependencia aún existan en el momento del plan/aplicación de Terraform.
Para su caso de uso específico, pruebe lo siguiente, utilizando el proveedor de aws preconstruido y S3BucketNotificationLambdaFunction para estructurar la configuración de la función lambda:
from cdktf_cdktf_provider_aws.s3 import S3BucketNotificationLambdaFunction, S3BucketNotification from cdktf_cdktf_provider_aws.lambda_function import LambdaFunction my_lambda_function = LambdaFunction( self, id='id', function_name='cdk-deployment-test', role='my-role', memory_size=128, runtime='python3.8', timeout=900, handler="lambda_handler", filename=os.path.join(os.getcwd(), 'deployment_package/package.zip') ) S3BucketNotification( self, id="s3-bucket-notification", bucket="my-bucket", lambda_function=[ S3BucketNotificationLambdaFunction( lambda_function_arn=my_lambda_function.arn, events=["s3:ObjectCreate"], filter_prefix="path" ) ] )