kbt.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import boto3
  2. REGION_NAME = 'us-east-1' # e.g
  3. import json
  4. def generate_sts_boto3():
  5. sts = boto3.client(
  6. 'sts',
  7. aws_access_key_id='AKIA2E67UIMD45Y3HL53',
  8. aws_secret_access_key='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',
  9. region_name=REGION_NAME
  10. )
  11. Policy = {"Version": "2012-10-17",
  12. "Statement": [{"Effect": "Allow", "Action": "kinesisvideo:*", "Resource": ['*']}]}
  13. credentials = sts.get_federation_token(
  14. Name='chanjunkai@163.com', # or any unique text related to user
  15. Policy=json.dumps(Policy),
  16. DurationSeconds=3600,
  17. )
  18. print(credentials)
  19. access_key_id = credentials['Credentials']['AccessKeyId']
  20. session_token = credentials['Credentials']['SessionToken']
  21. secret_access_key = credentials['Credentials']['SecretAccessKey']
  22. res = {
  23. 'access_key_id': access_key_id,
  24. 'secret_access_key': secret_access_key,
  25. 'session_token': session_token,
  26. }
  27. print(res)
  28. token_dict = {'access_key_id': 'ASIA2E67UIMDVTHGAEEV', 'secret_access_key': 'GncLAqpmcPS+4OjZt+xfg5hZrXDVYDH0jvaulunY',
  29. 'session_token': 'FwoGZXIvYXdzEBAaDKypPx1gg3gqmDdzfCK+AZ1Z/DS1ZK8jSzrOQnAeB70PnMBK+B7rVPXyiqIilx7gqCAg/xVne9X2bHAItg3b02dGkRrD57CWqHnAeLkpsLMXYxAZsZhgEXW11NmjIAQVc5ZiNyRI8LIvp8s8FrsLLm7zs57TdbPy6i9o1di1silEiwYRQc65iKMOfVH8cOg0iZA0mfDYksuxAmeAo5lQF6JX/7DujtJR/LNzqetv83F400I47vIStBbXtXkqp/qBVMfNIrN9wVA4fmLpvBEop8Gu7gUyKT34Cd4XhwvxdXt4bq8bKm3Bya553WMEsqh0xbG7WJLWP4+8GitU8YWb'}
  30. key = token_dict['access_key_id']
  31. secret = token_dict['secret_access_key']
  32. token = token_dict['session_token']
  33. boto3_session = boto3.Session(aws_access_key_id=key, aws_secret_access_key=secret, aws_session_token=token,
  34. region_name='us-east-1')
  35. kv_client = boto3_session.client('kinesisvideo')
  36. res = kv_client.describe_stream(StreamName='test_stream')
  37. print(res)