How to set uploaded image as featured image wordpress

Did you read doc for set_post_thumbnail()?

You need either post object or post ID for the set_post_thumbnail() function. The function wp_insert_post() will return post id on success. You can use that post id to set the thumbnail image.

Here is the modification for your last couple of lines

$post_id = wp_insert_post( $my_post );

if(!$post_id){
    // post insertion was failed. Handle it here
}

//Set Image as thumbnail
set_post_thumbnail($post_id, $attachment_id); //Don't know what to do with this

That should do it.

code not tested