SSL with cloudflare and AWS s3 and ELB

To work around CORS I modified my javascript code to use https://api.domain.com/api/v1/login
and thought of mapping api in Cloudflare to my AWS instances

I was hence thinking of
creating
(a) Cloudflare ([dns]) ---------> nginx -------> AWS ELB

I read about using NGINX as reverse proxy to avoid CORS but realised that Cloudflare itself
works as proxy

But then decided to use the following configuration

(b) Cloudflare([dns+proxy] orange cloud) <---------------> AWS ELB
added CNAME entry where I map api <.----------->AWS ELB.

Using (b) above, I created a origin certificate under SSL/TLS app of Cloudflare
and I read that we can use that certificate at entry point of AWS which is my ELB

So I expected
a) Browser invokes subdomain.domain.com (Points to s3 where frontend resides)

b) This fetches the javascript code and we make login API call
api.domain.com/api/v1/login

c) api is on Cloudflare which maps to AWS ELB and AWS ELB is configured to receive HTTPS on port 443 using the Cloudflare origin certificate

I am getting 521 error. Web server is down, when I access https://api.domain.com on the browser
Am I on the right track