我相信使用环境变量是正确的。我将使用机密管理器或系统管理器参数存储,使其成为依赖项,并将其注入函数环境
变量中。
如果不运行代码,我不确定<;资源>;。addDependency(<;other resource>;)
是必需的,但如果遇到任何操作的部署顺序问题,请注意这一点。。。
import * as cdk from aws-cdk-lib
import * as lambda from aws-cdk-lib/aws-lambda
import * as secretsmanager from aws-cdk-lib/aws-secretsmanager
import * as stepfunctions from aws-cdk-lib/aws-stepfunctions
export class Stack extends cdk.Stack implements cdk.Stack {
constructor(scope, id, props?: cdk.StackProps) {
super(scope, id, props)
const stateMachine = new stepfunctions.StateMachine(this, state-machine , {
definition: waitState,
})
const secret = secretsmanager.Secret(this, secret , {
secretObjectValue: {
machineArn: stateMachine.stateMachineArn,
},
})
// secret.node.addDependency(stateMachine)
const lambda = new lambda.Function(this, lambda , {
environment: {
STATE_MACHINE_ARN: dbSecret.secretValueFromJson( arn ).toString(),
},
})
// lambda.node.addDependency(secret)
}
}