簡體   English   中英

在 lambda 的 cdk 構造中使用公共 url 創建資產

[英]Creating asset with public url in cdk construct for lambda

我正在嘗試創建和部署一個CustomMessageTriggerHandler lambda 以自定義 Cognito 使用 cdk 發出的驗證消息,我想包含一個圖像資產以包含在 email 中。這需要是一個公共 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

包含在 email 返回 403。

是的,這將不起作用,因為資產最終將位於私有 S3 存儲桶中。 您不應使用資產。 相反,創建一個 S3 存儲桶並使用 S3Deployment 構造將圖片上傳到那里。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM