How do I insert a record and put the ID into an existing record in another table?
You can use DO block:

DO $$
DECLARE
    rows CURSOR FOR
        SELECT * FROM foos;
BEGIN
    FOR r IN rows LOOP
        WITH _ins AS (
            INSERT INTO aaa (foo) 
            VALUES (r.foo)
            RETURNING aaa.id AS aaa_id 
        )
        UPDATE foos
            SET aaa_id = (SELECT aaa_id FROM _ins)
            WHERE id = r.id;
    END LOOP;
END$$;