Lambda 함수 생성


  1. Lambda 함수
  2. 블루프린트 “s3-get-object” 사용
  3. 함수 이름 지정
  4. s3-object-readonly 권한이 있는 역할을 지정
  5. 로그가 수집되는 s3 버킷을 트리거로 지정, PUT, prefix는 “logs”
  6. 함수 생성

Lambda 함수 확인하기


  1. 초기 람다함수 확인
console.log('Loading function');

const aws = require('aws-sdk');

const s3 = new aws.S3({ apiVersion: '2006-03-01' });

exports.handler = async (event, context) => {
    // console.log('Received event:', JSON.stringify(event, null, 2));

    // Get the object from the event and show its content type
    const bucket = event.Records[0].s3.bucket.name;
    const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\\+/g, ' '));
    const params = {
        Bucket: bucket,
        Key: key,
    };
    try {
        const { ContentType } = await s3.getObject(params).promise();
        console.log('ContentType:', ContentType);
        return ContentType;
    } catch (err) {
        console.log(err);
        const message = `Error getting object ${key} from bucket ${bucket}. Make sure they exist and your bucket is in the same region as this function.`;
        console.log(message);
        throw new Error(message);
    }
};

Unzip Lambda 생성(실패)


<aside> 💡 참고자료 Unzip lambda 블로그

</aside>

  1. 람다 함수 생성