Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) S3 List Buckets using an STS Session TokenThis is an example showing how to use an STS session token in an Amazon AWS request. This example will list S3 buckets using a previously obtained session token.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- See Get AWS STS Session Token for sample code to get the session token XML. DECLARE @xmlToken int -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Xml', @xmlToken OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @xmlToken, 'LoadXmlFile', @success OUT, 'qa_data/tokens/aws_session_token.xml' IF @success = 0 BEGIN EXEC sp_OAGetProperty @xmlToken, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @xmlToken RETURN END DECLARE @rest int -- Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT -- Connect to the Amazon AWS REST server. DECLARE @bTls int SELECT @bTls = 1 DECLARE @port int SELECT @port = 443 DECLARE @bAutoReconnect int SELECT @bAutoReconnect = 1 EXEC sp_OAMethod @rest, 'Connect', @success OUT, 's3.amazonaws.com', @port, @bTls, @bAutoReconnect -- Provide AWS credentials for the REST call. DECLARE @authAws int -- Use "Chilkat_9_5_0.AuthAws" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.AuthAws', @authAws OUT -- The purpose of this example is to show how to use the temporary AccessKeyId, SecretAccessKey, and SessionToken. EXEC sp_OAMethod @xmlToken, 'GetChildContent', @sTmp0 OUT, 'GetSessionTokenResult|Credentials|AccessKeyId' EXEC sp_OASetProperty @authAws, 'AccessKey', @sTmp0 EXEC sp_OAMethod @xmlToken, 'GetChildContent', @sTmp0 OUT, 'GetSessionTokenResult|Credentials|SecretAccessKey' EXEC sp_OASetProperty @authAws, 'SecretKey', @sTmp0 EXEC sp_OASetProperty @authAws, 'ServiceName', 's3' EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws EXEC sp_OAMethod @xmlToken, 'GetChildContent', @sTmp0 OUT, 'GetSessionTokenResult|Credentials|SessionToken' EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'X-Amz-Security-Token', @sTmp0 DECLARE @sbResponse int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponse OUT EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/', @sbResponse IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @xmlToken EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @authAws EXEC @hr = sp_OADestroy @sbResponse RETURN END DECLARE @statusCode int EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @statusCode OUT PRINT 'Response status code = ' + @statusCode DECLARE @xml int -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT EXEC sp_OAMethod @xml, 'LoadSb', @success OUT, @sbResponse, 1 EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 IF @statusCode <> 200 BEGIN PRINT 'Failed. See error information in the XML.' EXEC @hr = sp_OADestroy @xmlToken EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @authAws EXEC @hr = sp_OADestroy @sbResponse EXEC @hr = sp_OADestroy @xml RETURN END EXEC @hr = sp_OADestroy @xmlToken EXEC @hr = sp_OADestroy @rest EXEC @hr = sp_OADestroy @authAws EXEC @hr = sp_OADestroy @sbResponse EXEC @hr = sp_OADestroy @xml END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.