How do I delete boto3 stream before trying to open one with same name?












0















I am using boto3 to fetch data using TwitterAPI. It opens a stream correctly the first time I run the program, but if I do a KeyboardInterupt in console and then try to run the program, I get the error:



botocore.errorfactory.ResourceInUseException: An error occurred 
(ResourceInUseException) when calling the CreateStream
operation: Stream TwitterStream under account XXXXXXXXXX already exists.


If I manually go in and change the name of the stream, I am able to create another stream, but this is kind of a hassle.



client = boto3.client('kinesis',region_name="us-east-2")
response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
access_token_secret)

kinesis = boto3.client('kinesis')


Any help would be appreciated.










share|improve this question



























    0















    I am using boto3 to fetch data using TwitterAPI. It opens a stream correctly the first time I run the program, but if I do a KeyboardInterupt in console and then try to run the program, I get the error:



    botocore.errorfactory.ResourceInUseException: An error occurred 
    (ResourceInUseException) when calling the CreateStream
    operation: Stream TwitterStream under account XXXXXXXXXX already exists.


    If I manually go in and change the name of the stream, I am able to create another stream, but this is kind of a hassle.



    client = boto3.client('kinesis',region_name="us-east-2")
    response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

    api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
    access_token_secret)

    kinesis = boto3.client('kinesis')


    Any help would be appreciated.










    share|improve this question

























      0












      0








      0








      I am using boto3 to fetch data using TwitterAPI. It opens a stream correctly the first time I run the program, but if I do a KeyboardInterupt in console and then try to run the program, I get the error:



      botocore.errorfactory.ResourceInUseException: An error occurred 
      (ResourceInUseException) when calling the CreateStream
      operation: Stream TwitterStream under account XXXXXXXXXX already exists.


      If I manually go in and change the name of the stream, I am able to create another stream, but this is kind of a hassle.



      client = boto3.client('kinesis',region_name="us-east-2")
      response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

      api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
      access_token_secret)

      kinesis = boto3.client('kinesis')


      Any help would be appreciated.










      share|improve this question














      I am using boto3 to fetch data using TwitterAPI. It opens a stream correctly the first time I run the program, but if I do a KeyboardInterupt in console and then try to run the program, I get the error:



      botocore.errorfactory.ResourceInUseException: An error occurred 
      (ResourceInUseException) when calling the CreateStream
      operation: Stream TwitterStream under account XXXXXXXXXX already exists.


      If I manually go in and change the name of the stream, I am able to create another stream, but this is kind of a hassle.



      client = boto3.client('kinesis',region_name="us-east-2")
      response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

      api = TwitterAPI(consumer_key, consumer_secret, access_token_key,
      access_token_secret)

      kinesis = boto3.client('kinesis')


      Any help would be appreciated.







      python amazon-web-services boto3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 17:54









      FlyromFlyrom

      193




      193
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Stream names are unique per account and region. So you can't recreate a stream that already exists. According to the create_stream docs:




          The stream name identifies the stream. The name is scoped to the AWS
          account used by the application. It is also scoped by AWS Region. That
          is, two streams in two different accounts can have the same name, and
          two streams in the same account, but in two different Regions, can
          have the same name.




          You will need to check if you need to create the stream or manage the error. Something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')


          Understand that when a stream is created you will need to wait for it to become ACTIVE - they are not usable instantly.



          Having said that, if you really want to delete it first change the code to something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))
          client.delete_stream(StreamName='TwitterStream')

          status = 'not set'
          while( status != 'ACTIVE' )
          describe_stream_response = client.describe_stream(stream_name)
          description = describe_stream_response.get('StreamDescription')
          status = description.get('StreamStatus')
          time.sleep(1)

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')





          share|improve this answer


























          • Thanks a bunch, really appreciate it :)

            – Flyrom
            Jan 1 at 21:57











          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/3.0/"u003ecc by-sa 3.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%2f53997661%2fhow-do-i-delete-boto3-stream-before-trying-to-open-one-with-same-name%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









          1














          Stream names are unique per account and region. So you can't recreate a stream that already exists. According to the create_stream docs:




          The stream name identifies the stream. The name is scoped to the AWS
          account used by the application. It is also scoped by AWS Region. That
          is, two streams in two different accounts can have the same name, and
          two streams in the same account, but in two different Regions, can
          have the same name.




          You will need to check if you need to create the stream or manage the error. Something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')


          Understand that when a stream is created you will need to wait for it to become ACTIVE - they are not usable instantly.



          Having said that, if you really want to delete it first change the code to something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))
          client.delete_stream(StreamName='TwitterStream')

          status = 'not set'
          while( status != 'ACTIVE' )
          describe_stream_response = client.describe_stream(stream_name)
          description = describe_stream_response.get('StreamDescription')
          status = description.get('StreamStatus')
          time.sleep(1)

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')





          share|improve this answer


























          • Thanks a bunch, really appreciate it :)

            – Flyrom
            Jan 1 at 21:57
















          1














          Stream names are unique per account and region. So you can't recreate a stream that already exists. According to the create_stream docs:




          The stream name identifies the stream. The name is scoped to the AWS
          account used by the application. It is also scoped by AWS Region. That
          is, two streams in two different accounts can have the same name, and
          two streams in the same account, but in two different Regions, can
          have the same name.




          You will need to check if you need to create the stream or manage the error. Something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')


          Understand that when a stream is created you will need to wait for it to become ACTIVE - they are not usable instantly.



          Having said that, if you really want to delete it first change the code to something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))
          client.delete_stream(StreamName='TwitterStream')

          status = 'not set'
          while( status != 'ACTIVE' )
          describe_stream_response = client.describe_stream(stream_name)
          description = describe_stream_response.get('StreamDescription')
          status = description.get('StreamStatus')
          time.sleep(1)

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')





          share|improve this answer


























          • Thanks a bunch, really appreciate it :)

            – Flyrom
            Jan 1 at 21:57














          1












          1








          1







          Stream names are unique per account and region. So you can't recreate a stream that already exists. According to the create_stream docs:




          The stream name identifies the stream. The name is scoped to the AWS
          account used by the application. It is also scoped by AWS Region. That
          is, two streams in two different accounts can have the same name, and
          two streams in the same account, but in two different Regions, can
          have the same name.




          You will need to check if you need to create the stream or manage the error. Something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')


          Understand that when a stream is created you will need to wait for it to become ACTIVE - they are not usable instantly.



          Having said that, if you really want to delete it first change the code to something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))
          client.delete_stream(StreamName='TwitterStream')

          status = 'not set'
          while( status != 'ACTIVE' )
          describe_stream_response = client.describe_stream(stream_name)
          description = describe_stream_response.get('StreamDescription')
          status = description.get('StreamStatus')
          time.sleep(1)

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')





          share|improve this answer















          Stream names are unique per account and region. So you can't recreate a stream that already exists. According to the create_stream docs:




          The stream name identifies the stream. The name is scoped to the AWS
          account used by the application. It is also scoped by AWS Region. That
          is, two streams in two different accounts can have the same name, and
          two streams in the same account, but in two different Regions, can
          have the same name.




          You will need to check if you need to create the stream or manage the error. Something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')


          Understand that when a stream is created you will need to wait for it to become ACTIVE - they are not usable instantly.



          Having said that, if you really want to delete it first change the code to something like:



          try:
          client = boto3.client('kinesis',region_name="us-east-2")
          response = client.create_stream(StreamName='TwitterStream',ShardCount=1)

          print('stream {} created'.format(stream_name))
          except ResourceInUseException:
          print('stream {} already exists'.format(stream_name))
          client.delete_stream(StreamName='TwitterStream')

          status = 'not set'
          while( status != 'ACTIVE' )
          describe_stream_response = client.describe_stream(stream_name)
          description = describe_stream_response.get('StreamDescription')
          status = description.get('StreamStatus')
          time.sleep(1)

          api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

          kinesis = boto3.client('kinesis')






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 21:30

























          answered Jan 1 at 21:19









          stdunbarstdunbar

          5,84561528




          5,84561528













          • Thanks a bunch, really appreciate it :)

            – Flyrom
            Jan 1 at 21:57



















          • Thanks a bunch, really appreciate it :)

            – Flyrom
            Jan 1 at 21:57

















          Thanks a bunch, really appreciate it :)

          – Flyrom
          Jan 1 at 21:57





          Thanks a bunch, really appreciate it :)

          – Flyrom
          Jan 1 at 21:57




















          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%2f53997661%2fhow-do-i-delete-boto3-stream-before-trying-to-open-one-with-same-name%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith