在lambda的cdk构造中使用公共url创建资产



我正在尝试创建和部署一个CustomMessageTriggerHandlerlambda,用于自定义使用cdk由Cognito发送的验证消息,并且我想在电子邮件中包含一个图像资产。这将需要是一个公共url,但我正在努力更新其权限,以便它不会返回403访问拒绝。

下面是我试过的代码:

export class MyServiceStack extends Stack {
constructor(app: Construct, id: string, props: MyServiceStackProps) {
super(app, id, props)
const imageAsset = new Asset(this, 'logo', {
path: join(__dirname, './assets/logo.png')
})
imageAsset.bucket.grantPublicAccess() // this was my attempt to allow public reads
const customizeVerificationMessage = new NodejsFunction(
this,
'customizeVerificationMessage',
{
//...other config
environment: {
LOGO_URL: imageAsset.httpUrl
}
}
)
// ...other code
const userPool = new UserPool(this, 'userpool', {
//...other config
lambdaTriggers: {
//...other triggers
customMessage: customizeVerificationMessage
},
})
}
}     

我期望这段代码会创建一个可公开访问的资产,但是

imageAsset.httpUrl

包含在邮件中的返回403。

是的,这将不起作用,因为资产将最终在私有S3 Bucket中。你不应该使用资产。而是创建一个S3存储桶,并使用S3Deployment构造在那里上传图片。

最新更新