Key interest features:
- function will send upload requests(PutObjectCommand) to S3 bucket, generated QR codes(.png),
to do that the function requires permissions for that specific bucket, in order to do that at function configuration level
asrole
property 👀 src/functions/create-and-upload-qrs/index.ts
export const generateUploadQr: AWS["functions"]["generateUploadQr"] = {
handler: `${handlerPath(__dirname)}/handler.generateUploadQr`,
role: "arn:aws:iam::${aws:accountId}:role/QRBucketGetAdd",
events: [
-
function will implement middy middlewares, JsonBodyParser that's almost default, Validator will validate event.body as Json Schema src/functions/create-and-upload-qrs/schema.ts, this case checks for the pressence of
productId
(string) in body object.
Maybe a bit more interesting is SSM That will fetch AWS System Manager parameter store, we use this instead of.env
files remember that your lambda will require permission for that too. HttpErrorHandler will take care of return http erros thrown at runtime. -
QR codes are generated by qrcode lib, then will encode(binary) to base64 Buffer prior to upload to target S3 Bucket