I am currently learning AWS by following Pluralsight course AWS Developer: Getting Started. As a part of this course, a nodejs app(a pizza creating an app) need to deploy in AWS. This app runs on EC2 instance and when we create a new pizza and click create, a png file will be saved into an S3 bucket(Code running in the EC2 instance will write to S3).
When I triggered this app with load balancer URL, app loaded and when I try to save the newly created pizza(a png image), web page freezes and file not saving into s3.
But, if I associate an Elastic IP to one of the instances in the target group, the file is saving properly into S3.
Regarding permissions to the EC2 instance, the security group has only load balancer other than SSH.
And EC2 has full S3 access role.
But, still the app is working only if Elastic IP is associated even though the Elastic IP is unusable(as target group EC2 security group has only load balancer access other then SSH)
Why Elastic IP is needed in this case for the correct behavior.
Edit: Additional information:
S3 bucket: full public access is given.
Here below PUT
allowed methods might be invalid. As a trail and error I provided this.
My Subnet Route configuration. I thought this is public subnet. Please correct me if I am wrong.
My assumption: I might be completely wrong but my understanding is that my subnet is public subnet and my ec2 instances are creating in this subnet. The EC2 instance(with full s3 access role) has a code to write PNG files to S3 with above settings(all public as per my understanding).
Hence I am expecting this ec2 should write file to S3 without Elastic IP.
But understood if auto assign IP addresses are enabled it is exactly in similar state as I am assigning Elastic IP's manually to EC2 and hence this scenario is working.
I understood that each EC2 instance will be assigned a different public IP address after enabling auto assign IP addresses. For this kind of requirements, Is this good method to go?
Having multiple public IP addresses assigned even though not using it(means will run only load balancer URL browser to access app not public IP) will cost more money?
There are generally three ways in which your instance can access S3 to upload your pizza file:
Your description seems to indicate that option 1 applies to you.
There could be other possibilities, e.g. S3 bucket has a bucket policy which allows uploads only from whitelisted IPs or IP ranges. Thus, maybe your elastic IP is whitelisted, while other IPs are not.