I'm creating a Secret in CDK like so:
import * as cdk from "@aws-cdk/core";
import * as lambda from "@aws-cdk/aws-lambda-nodejs";
import * as apiGw from "@aws-cdk/aws-apigateway";
import * as secretsmanager from "@aws-cdk/aws-secretsmanager";
export class ObjectCdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const secret = new secretsmanager.Secret(this, "MasterSecret");
const handler = new lambda.NodejsFunction(this, "HelloHandler", {
entry: "lambda/hello.ts",
bundling: {
nodeModules: ["uuid"],
},
environment: {
MASTER_SECRET: secret.secretValue.toString(),
},
});
new apiGw.LambdaRestApi(this, "Endpoint", {
handler,
});
new cdk.CfnOutput(this, "MasterSecretValue", {
value: secret.secretValue.toString(),
});
}
}
And I want to use that secret to make authorized requests to my lambda function. The only solution I could come up with is to put a log in the lambda code and check the AWS logs online to copy the secret. Surely there's another way?