How do I delete boto3 stream before trying to open one with same name?
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
add a comment |
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
add a comment |
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
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
python amazon-web-services boto3
asked Jan 1 at 17:54
FlyromFlyrom
193
193
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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')
Thanks a bunch, really appreciate it :)
– Flyrom
Jan 1 at 21:57
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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')
Thanks a bunch, really appreciate it :)
– Flyrom
Jan 1 at 21:57
add a comment |
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')
Thanks a bunch, really appreciate it :)
– Flyrom
Jan 1 at 21:57
add a comment |
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')
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')
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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