How to fix simple http server written in python 3 using Terraform on AWS EC2 CentosGetting a cherrypy Hello World running on EC2 instanceNode.js on RedHat and Amazon EC2authbind equivalent for centos / amazon linux / rhelStarting http-server on Amazon EC2Simple Python TCP server not working on Amazon EC2 instanceHow to deploy Python Flask app to Apache (Httpd) running on Amazon Linux EC2 instanceAWS Apache in Public and Tomcat in Private Subnetsaws EC2 linux unable to open inbound portsCan't access Windows EC2 instance from public ipWhy does AWS firewall not permit remote connection from my work computer?

Amortized Loans seem to benefit the bank more than the customer

Are there any “Third Order” acronyms used in space exploration?

Why does the speed of sound decrease at high altitudes although the air density decreases?

How to give my students a straightedge instead of a ruler

How much would a 1 foot tall human weigh?

How do we know that black holes are spinning?

How to create an animated flowchart with LaTeX?

What was the ultimate objective of The Party in 1984?

Can a character with good/neutral alignment attune to a sentient magic item with evil alignment?

What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)

Why is this sentence grammatical?

How do certain apps show new notifications when internet access is restricted to them?

Why is the year in this ISO timestamp not 2019?

Wrong Schengen Visa exit stamp on my passport, who can I complain to?

What 68-pin connector is this on my 2.5" solid state drive?

Can derivatives be defined as anti-integrals?

Meaning of Swimming their horses

Why is my fire extinguisher emptied after one use?

Make 2019 with single digits

How to write characters doing illogical things in a believable way?

How would you control supersoldiers in a late iron-age society?

How can I use expandafter the expand the definition of this control sequence?

What would happen if Protagoras v Euathlus were heard in court today?

Teleport everything in a large zone; or teleport all living things and make a lot of equipment disappear



How to fix simple http server written in python 3 using Terraform on AWS EC2 Centos


Getting a cherrypy Hello World running on EC2 instanceNode.js on RedHat and Amazon EC2authbind equivalent for centos / amazon linux / rhelStarting http-server on Amazon EC2Simple Python TCP server not working on Amazon EC2 instanceHow to deploy Python Flask app to Apache (Httpd) running on Amazon Linux EC2 instanceAWS Apache in Public and Tomcat in Private Subnetsaws EC2 linux unable to open inbound portsCan't access Windows EC2 instance from public ipWhy does AWS firewall not permit remote connection from my work computer?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm initiating new AWS EC2 instance using terraform main.tf for Centos AMI. I'm able to create and connect the AWS instance.



but I have below problem



  • When, I start simple python 3 based http server which is simply printing "hello world", I can't able to run python script using file function from terraform. can anyone help me how to execute. shall I use function or use
    resource "null_resource" "cluster" {
    using interpreter?

  • from the outside world, I can't able to connect the public domain:exposed port(using curl http://publicip:8080). Though I have created a security group.

Can anyone help me out...Is there any possibilities, to check in terraform that these resources are indeed created in AWS EC2 instance. like some kind of debugging log.



PS: my EC2 instance has default python2.7 installed so in main.tf I tried to install python3 using to execute python script and this python script works fine in my local.



Or is there any best approach to execute this.
I'm still learning AWS using terraform.



simple-hello-world.py



from http.server import BaseHTTPRequestHandler, HTTPServer


# HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):

# GET
def do_GET(self):
# Send response status code
self.send_response(200)

# Send headers
self.send_header('Content-type', 'text/html')
self.end_headers()

# Send message back to client
message = "Hello world!"
# Write content as utf-8 data
self.wfile.write(bytes(message, "utf8"))
return


def run():
print('starting server...')

# Server settings
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
server_address = ('127.0.0.1', 8081)
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
print('running server...')
httpd.serve_forever()


run()



main.tf




provider "aws"
region = "us-east-2"
version = "~> 1.2.0"


resource "aws_instance" "hello-world"
ami = "ami-ef92b08a"
instance_type = "t2.micro"

provisioner "local-exec"
command = <<EOH
sudo yum -y update
sudo yum install -y python3.6
EOH


user_data = "$file("$path.module/simple-hello-world.py")"

tags
Name = "my-aws-terraform-hello-world"



resource "aws_security_group" "allow-tcp"
name = "my-aws-terraform-hello-world"
ingress
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]











share|improve this question






























    0















    I'm initiating new AWS EC2 instance using terraform main.tf for Centos AMI. I'm able to create and connect the AWS instance.



    but I have below problem



    • When, I start simple python 3 based http server which is simply printing "hello world", I can't able to run python script using file function from terraform. can anyone help me how to execute. shall I use function or use
      resource "null_resource" "cluster" {
      using interpreter?

    • from the outside world, I can't able to connect the public domain:exposed port(using curl http://publicip:8080). Though I have created a security group.

    Can anyone help me out...Is there any possibilities, to check in terraform that these resources are indeed created in AWS EC2 instance. like some kind of debugging log.



    PS: my EC2 instance has default python2.7 installed so in main.tf I tried to install python3 using to execute python script and this python script works fine in my local.



    Or is there any best approach to execute this.
    I'm still learning AWS using terraform.



    simple-hello-world.py



    from http.server import BaseHTTPRequestHandler, HTTPServer


    # HTTPRequestHandler class
    class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):

    # GET
    def do_GET(self):
    # Send response status code
    self.send_response(200)

    # Send headers
    self.send_header('Content-type', 'text/html')
    self.end_headers()

    # Send message back to client
    message = "Hello world!"
    # Write content as utf-8 data
    self.wfile.write(bytes(message, "utf8"))
    return


    def run():
    print('starting server...')

    # Server settings
    # Choose port 8080, for port 80, which is normally used for a http server, you need root access
    server_address = ('127.0.0.1', 8081)
    httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
    print('running server...')
    httpd.serve_forever()


    run()



    main.tf




    provider "aws"
    region = "us-east-2"
    version = "~> 1.2.0"


    resource "aws_instance" "hello-world"
    ami = "ami-ef92b08a"
    instance_type = "t2.micro"

    provisioner "local-exec"
    command = <<EOH
    sudo yum -y update
    sudo yum install -y python3.6
    EOH


    user_data = "$file("$path.module/simple-hello-world.py")"

    tags
    Name = "my-aws-terraform-hello-world"



    resource "aws_security_group" "allow-tcp"
    name = "my-aws-terraform-hello-world"
    ingress
    from_port = 8080
    to_port = 8080
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]











    share|improve this question


























      0












      0








      0








      I'm initiating new AWS EC2 instance using terraform main.tf for Centos AMI. I'm able to create and connect the AWS instance.



      but I have below problem



      • When, I start simple python 3 based http server which is simply printing "hello world", I can't able to run python script using file function from terraform. can anyone help me how to execute. shall I use function or use
        resource "null_resource" "cluster" {
        using interpreter?

      • from the outside world, I can't able to connect the public domain:exposed port(using curl http://publicip:8080). Though I have created a security group.

      Can anyone help me out...Is there any possibilities, to check in terraform that these resources are indeed created in AWS EC2 instance. like some kind of debugging log.



      PS: my EC2 instance has default python2.7 installed so in main.tf I tried to install python3 using to execute python script and this python script works fine in my local.



      Or is there any best approach to execute this.
      I'm still learning AWS using terraform.



      simple-hello-world.py



      from http.server import BaseHTTPRequestHandler, HTTPServer


      # HTTPRequestHandler class
      class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):

      # GET
      def do_GET(self):
      # Send response status code
      self.send_response(200)

      # Send headers
      self.send_header('Content-type', 'text/html')
      self.end_headers()

      # Send message back to client
      message = "Hello world!"
      # Write content as utf-8 data
      self.wfile.write(bytes(message, "utf8"))
      return


      def run():
      print('starting server...')

      # Server settings
      # Choose port 8080, for port 80, which is normally used for a http server, you need root access
      server_address = ('127.0.0.1', 8081)
      httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
      print('running server...')
      httpd.serve_forever()


      run()



      main.tf




      provider "aws"
      region = "us-east-2"
      version = "~> 1.2.0"


      resource "aws_instance" "hello-world"
      ami = "ami-ef92b08a"
      instance_type = "t2.micro"

      provisioner "local-exec"
      command = <<EOH
      sudo yum -y update
      sudo yum install -y python3.6
      EOH


      user_data = "$file("$path.module/simple-hello-world.py")"

      tags
      Name = "my-aws-terraform-hello-world"



      resource "aws_security_group" "allow-tcp"
      name = "my-aws-terraform-hello-world"
      ingress
      from_port = 8080
      to_port = 8080
      protocol = "tcp"
      cidr_blocks = ["0.0.0.0/0"]











      share|improve this question














      I'm initiating new AWS EC2 instance using terraform main.tf for Centos AMI. I'm able to create and connect the AWS instance.



      but I have below problem



      • When, I start simple python 3 based http server which is simply printing "hello world", I can't able to run python script using file function from terraform. can anyone help me how to execute. shall I use function or use
        resource "null_resource" "cluster" {
        using interpreter?

      • from the outside world, I can't able to connect the public domain:exposed port(using curl http://publicip:8080). Though I have created a security group.

      Can anyone help me out...Is there any possibilities, to check in terraform that these resources are indeed created in AWS EC2 instance. like some kind of debugging log.



      PS: my EC2 instance has default python2.7 installed so in main.tf I tried to install python3 using to execute python script and this python script works fine in my local.



      Or is there any best approach to execute this.
      I'm still learning AWS using terraform.



      simple-hello-world.py



      from http.server import BaseHTTPRequestHandler, HTTPServer


      # HTTPRequestHandler class
      class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):

      # GET
      def do_GET(self):
      # Send response status code
      self.send_response(200)

      # Send headers
      self.send_header('Content-type', 'text/html')
      self.end_headers()

      # Send message back to client
      message = "Hello world!"
      # Write content as utf-8 data
      self.wfile.write(bytes(message, "utf8"))
      return


      def run():
      print('starting server...')

      # Server settings
      # Choose port 8080, for port 80, which is normally used for a http server, you need root access
      server_address = ('127.0.0.1', 8081)
      httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
      print('running server...')
      httpd.serve_forever()


      run()



      main.tf




      provider "aws"
      region = "us-east-2"
      version = "~> 1.2.0"


      resource "aws_instance" "hello-world"
      ami = "ami-ef92b08a"
      instance_type = "t2.micro"

      provisioner "local-exec"
      command = <<EOH
      sudo yum -y update
      sudo yum install -y python3.6
      EOH


      user_data = "$file("$path.module/simple-hello-world.py")"

      tags
      Name = "my-aws-terraform-hello-world"



      resource "aws_security_group" "allow-tcp"
      name = "my-aws-terraform-hello-world"
      ingress
      from_port = 8080
      to_port = 8080
      protocol = "tcp"
      cidr_blocks = ["0.0.0.0/0"]








      python-3.x amazon-ec2 centos terraform-provider-aws simplehttpserver






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 12:09









      Manas SamantarayManas Samantaray

      419 bronze badges




      419 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          1 - You are uploading the script, but you are not executing it. You will have to call it just like you did to install python, using local-exec.



          2 - You opened port 8080, but your application runs on 8081.






          share|improve this answer

























          • ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

            – Manas Samantaray
            Mar 29 at 11:23











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397307%2fhow-to-fix-simple-http-server-written-in-python-3-using-terraform-on-aws-ec2-cen%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0
















          1 - You are uploading the script, but you are not executing it. You will have to call it just like you did to install python, using local-exec.



          2 - You opened port 8080, but your application runs on 8081.






          share|improve this answer

























          • ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

            – Manas Samantaray
            Mar 29 at 11:23
















          0
















          1 - You are uploading the script, but you are not executing it. You will have to call it just like you did to install python, using local-exec.



          2 - You opened port 8080, but your application runs on 8081.






          share|improve this answer

























          • ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

            – Manas Samantaray
            Mar 29 at 11:23














          0














          0










          0









          1 - You are uploading the script, but you are not executing it. You will have to call it just like you did to install python, using local-exec.



          2 - You opened port 8080, but your application runs on 8081.






          share|improve this answer













          1 - You are uploading the script, but you are not executing it. You will have to call it just like you did to install python, using local-exec.



          2 - You opened port 8080, but your application runs on 8081.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 28 at 12:47









          StargazerStargazer

          7405 silver badges8 bronze badges




          7405 silver badges8 bronze badges















          • ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

            – Manas Samantaray
            Mar 29 at 11:23


















          • ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

            – Manas Samantaray
            Mar 29 at 11:23

















          ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

          – Manas Samantaray
          Mar 29 at 11:23






          ahhh!!! silly of me..I thought I opened it for 8080 in the python.Do you think, provisioner "local-exec" command = <<EOH sudo yum -y update sudo yum install -y python3.6 n python3 "$path.module/simple-hello-world.py" EOH

          – Manas Samantaray
          Mar 29 at 11:23









          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397307%2fhow-to-fix-simple-http-server-written-in-python-3-using-terraform-on-aws-ec2-cen%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현