0

I have step function with lambda_1 as starting point.

This step function is going to be triggered when object is added to S3. I am getting the event and trying to fetch objectKey and bucket from that .

This is my lambda handler written in TypeScript:

export const handler: Handler<EventBridgeEvent<'Object Created', S3EventDetail>> = async (event) => {
//....
const { bucket, object } = event.detail;
}

S3EventDetail is a type I created to match with eventBridge structure

interface S3EventDetail {
    detail: {
        version: string;
        bucket: {
            name: string;
        };
        object: {
            key: string;
            size: number;
            etag: string;
            'version-id': string;
            sequencer: string;
        };
        'request-id': string;
        requester: string;
        'source-ip-address': string;
        reason: string;
    }; 
    version: string;
    id: string;
    'detail-type': string;
    source: string;
    account: string;
    time: string;
    region: string;
    resources: string[];
   
}

I get bucket or object using this line

const { bucket, object } = event.detail;

when I run the code with a sample event it works, but when I build I get the error

Property 'bucket' does not exist on type 'S3EventDetail'.
3
  • console.log out event to ensure it is truly matching your interface. Commented Jul 8 at 0:43
  • @PatrickatCloudBudgie the event structure I see in console log is what I want (S3EventDetail) but when I want to user the properties , it cant be built
    – Sara N
    Commented Jul 9 at 13:30
  • Hmmm. Well the error is correct - bucket does not exist on S3EventDetail. It exists on S3EventDetail.detail. Is the build error definitely coming from the line you show above? Commented Jul 12 at 0:40

0