Amazon has returned to profitability by posting a $6.7 billion profit for the second quarter, against losses of about $2 billion in the year-ago period, as the e-commerce giant registered better-than-expected sales.