AWS SDK For C - Developer Guide

1y ago
12 Views
3 Downloads
1.24 MB
206 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Tripp Mcmullen
Transcription

AWS SDK for C Developer GuideAWS SDK for C : Developer GuideCopyright Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

AWS SDK for C Developer GuideAmazon's trademarks and trade dress may not be used in connection with any product or service that is notAmazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages ordiscredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who mayor may not be affiliated with, connected to, or sponsored by Amazon.

AWS SDK for C Developer GuideTable of ContentsAWS SDK for C Developer Guide . 1Additional documentation and resources . 1Maintenance and support for SDK major versions . 1Getting started . 2Providing AWS credentials . 2Create an AWS account and administrator user . 2Create AWS credentials and a profile . 3More information on user credentials . 3Getting the SDK from source . 4Build on Windows . 4Build on Linux/macOS . 7"Hello S3" app . 9Getting the SDK from a package manager . 13Getting the SDK using vcpkg . 13Getting the SDK using NuGet (deprecated) . 13Build on Windows . 13Build on Linux/macOS . 15"Hello S3" app . 16Troubleshooting build issues . 18CMake Error: Could not find a package configuration file provided by "AWSSDK" . 18CMake Error: Could not find load file (and you're on SDK version 1.8) . 18CMake Error: Could not find load file . 19Runtime Error: cannot proceed because aws-*.dll was not found . 19Configuring the SDK . 21CMake parameters . 21General CMake Variables and Options . 21Android CMake Variables and Options . 26Overriding your HTTP client . 28Controlling iostreams used by the HttpClient and the AWSClient . 28Using the SDK . 29Basic Use . 29Initializing and Shutting Down the SDK . 29Setting SDK Options . 30AWS Client configuration . 30Configuration Variables . 31Service Client Classes . 33Utility Modules . 33HTTP Stack . 33String Utils . 34Hashing Utils . 34JSON Parser . 34XML Parser . 34Memory Management . 34Allocating and Deallocating Memory . 35STL and AWS Strings and Vectors . 35Remaining Issues . 36Native SDK Developers and Memory Controls . 36Logging . 37Error Handling . 38Working with AWS services . 40Getting started on code examples . 40Structure of the code examples . 40Using AWS for troubleshooting and diagnostics . 41Building and Debugging Code Examples in Visual Studio . 43iii

AWS SDK for C Developer GuideAsynchronous methods . 44Asynchronous SDK methods . 44Calling SDK asynchronous methods . 45Notification of the Completion of an Asynchronous Operation . 46Code examples with guidance . 48Amazon CloudWatch examples . 48Amazon DynamoDB examples . 59Amazon EC2 examples . 68AWS Identity and Access Management examples . 86Amazon S3 examples . 105Amazon SQS examples . 132Additional code examples . 143Single-service actions and scenarios . 143Security . 191Data Protection . 191Identity and Access Management . 192Compliance Validation . 192Resilience . 193Infrastructure Security . 193Enforcing a minimum TLS version . 193Enforce TLS 1.2 with libcurl on all platforms . 194Enforce TLS 1.2 on Windows . 194Amazon S3 Encryption Client Migration . 196Migration Overview . 196Update Existing Clients to Read New Formats . 196Migrate Encryption and Decryption Clients to V2 . 197Additional Examples . 198Document history . 201iv

AWS SDK for C Developer GuideAdditional documentation and resourcesAWS SDK for C Developer GuideWelcome to the AWS SDK for C Developer Guide.The AWS SDK for C provides a modern C (version C 11 or later) interface for Amazon WebServices (AWS). It provides both high-level and low-level APIs for nearly all AWS features, minimizingdependencies and providing platform portability on Windows, macOS, Linux, and mobile.Getting started using the AWS SDK for C (p. 2)NoteThe AWS IoT SDKs and the aws-iot-device-sdk-cpp are separate from this SDK. The AWSIoT Device SDK for C v2 is available at aws-iot-device-sdk-cpp-v2 on GitHub.For more information about AWS IoT, see What is AWS IoT in the AWS IoT Developer Guide.Additional documentation and resourcesIn addition to this guide, the following are valuable online resources for AWS SDK for C developers: AWS SDKs and Tools Reference Guide: Contains settings, features, and other foundational conceptscommon amongst AWS SDKs. GitHub: SDK source SDK issues AWS SDK for C API Reference AWS C Developer Blog The AWS Code Sample Catalog SDK License Video: Introducing the AWS SDK for C from AWS re:invent 2015Maintenance and support for SDK major versionsFor information about maintenance and support for SDK major versions and their underlyingdependencies, see the following in the AWS SDKs and Tools Reference Guide: AWS SDKs and tools maintenance policy AWS SDKs and tools version support matrix1

AWS SDK for C Developer GuideProviding AWS credentialsGetting started using the AWS SDKfor C AWS SDK for C is a modularized, cross-platform, open-source library you can use to connect toAmazon Web Services.The AWS SDK for C uses CMake to support multiple platforms over multiple domains, including videogames, systems, mobile, and embedded devices. CMake is a build tool that you can use to manage yourapplication’s dependencies and to create makefiles suitable for the platform you’re building on. CMakeremoves the parts of the build that are not used for your platform or application.Before you run code to access AWS resources, you must establish your AWS user credentials in yourenvironment. Providing AWS credentials (p. 2)To use the AWS SDK for C in your code, obtain the SDK executables by building the SDK source directlyor by using a package manager. Getting the AWS SDK for C from source code (p. 4) Getting the AWS SDK for C from a package manager (p. 13)If you run into build issues regarding CMake, see Troubleshooting build issues (p. 18).Providing AWS credentialsTo connect to any of the supported services with the AWS SDK for C , you must provide AWScredentials. The AWS SDKs and CLIs use provider chains to look for AWS credentials in several differentplaces, including system/user environment variables and local AWS configuration files. For details, seeCredentials Providers in the aws-sdk-cpp repository in GitHub.Create an AWS account and administrator user1.Create an account.To create an AWS account, see How do I create and activate a new AWS account?2.Create an administrative user.Avoid using your AWS account root user (the initial account you create) to access the AWSManagement Console and services. Instead, create an administrative user account, as explained inCreating your first IAM admin user and group.After you create the administrative user account and record the login details, sign out of your AWSaccount root user and sign back in using the administrative account.2

AWS SDK for C Developer GuideCreate AWS credentials and a profileCreate AWS credentials and a profileTo use the SDK, create an AWS Identity and Access Management (IAM) user and obtain credentials forthat user. Then make them available to the SDK in your development environment by saving them to theAWS shared credentials file.To create and use credentials1.Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.2.Choose Users, and then choose Add user.3.Enter a user name. For this tutorial, we'll use SdkUser.4.5.Under Select AWS access type, select Programmatic access, and then choose Next: Permissions.Choose Attach existing policies directly.6.In Search, enter s3, and then select AmazonS3FullAccess.7.Choose Next: Tags, Next: Review, and Create user.8.On the Success screen, choose Download .csv.The downloaded file contains the Access Key ID and the Secret Access Key for this IAM user.Note9.You will not have another opportunity to download or copy the Secret Access Key.Treat your Secret Access Key as a password; save in a trusted location and do not share it.WarningUse appropriate security measures to keep these credentials safe and rotated.10. Create or open the AWS shared credentials file. This file is /.aws/credentials on Linux andmacOS systems, and %USERPROFILE%\.aws\credentials on Windows.11. Add the following text to the AWS shared credentials file, but replace the example ID value andexample key value with the ones you obtained earlier. Save the file. See Location of Credentials Filesfor more information.[default]aws access key id AKIAIOSFODNN7EXAMPLEaws secret access key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYThe preceding procedure is the simplest of several possibilities for authentication and authorization. Forother options, see below.More information on user credentialsTo explore other ways to provide credentials to SDKs, see the following: To create long-term AWS credentials, see Programmatic access in the AWS General Reference. To create short-term AWS credentials, see Temporary Security Credentials in the IAM User Guide. To learn more about supported provider chains, see the AWS SDKs and Tools Reference Guide,specifically: The .aws/credentials and .aws/config files Using environment variables role arn (corresponds to the AWS ROLE ARN environment variable) web identity token file (corresponds to the AWS WEB IDENTITY TOKEN FILE environmentvariable)3

AWS SDK for C Developer GuideGetting the SDK from source role session name (corresponds to the AWS ROLE SESSION NAME environment variable) To learn more about the AWS CONTAINER CREDENTIALS RELATIVE URI environment variable, seeIAM Roles for Tasks in the Amazon Elastic Container Service Developer Guide.Getting the AWS SDK for C from source codeYou can use the AWS SDK for C from your code by first building the SDK from source and theninstalling it locally.Process overviewGeneral processDetailed processBuild and install the SDK sourceFirst build the SDK from source and install it.1. Build on Windows (p. 4) Build on Linux/macOS (p. 7)2.3.Use CMake to generate build files for theSDK.Build the SDK.Install the SDK.Build your application using the SDKThen develop your own application using the SDK.1.Write your own code to use the SDK or usea sample application, and add the AWSSDKpackage to your cmake file. "Hello, S3!" starter application (p. 9)2.3.Use CMake to generate build files for yourapplication.Build your application.4.Run your application.Building the AWS SDK for C on WindowsTo set up the AWS SDK for C , you can either build the SDK yourself directly from the source ordownload the libraries using a package manager.The SDK source is separated into individual packages by service. Installing the entire SDK can take up toan hour. Installing only the specific subset of services that your program uses decreases installation timeand also reduces size on disk. To choose which services to install, you need to know the package nameof each service your program uses. You can see the list of package directories at aws/aws-sdk-cpp onGitHub. The package name is the suffix of the directory name for the service.aws-sdk-cpp\aws-cpp-sdk- packageName aws-sdk-cpp\aws-cpp-sdk-s3# Repo directory name and packageName# Example: Package name is s3PrerequisitesYou need a minimum of 4 GB of RAM to build some of the larger AWS clients. The SDK might fail tobuild on Amazon EC2 instance types t2.micro, t2.small, and other small instance types due to insufficientmemory.To use the AWS SDK for C , you need one of the following:4

AWS SDK for C Developer GuideBuild on Windows Microsoft Visual Studio 2015 or later, GNU Compiler Collection (GCC) 4.9 or later, or Clang 3.3 or later.Building the SDK for Windows with curlOn Windows, the SDK is built with WinHTTP as the default HTTP client. However, WinHTTP 1.0 doesnot support HTTP/2 bidirectional streaming, which is required for some AWS services such as AmazonTranscribe and Amazon Lex. Thus, it is sometimes necessary to build curl support with the SDK. To viewall available curl download options, see curl Releases and Downloads. One method for building the SDKwith curl support is the following:To build the SDK with curl library support included1.Navigate to curl for Windows and download the curl binary package for Microsoft Windows.2.3.Unpack the package to a folder on your computer, for example, C:\curl.Navigate to CA certificates extracted from Mozilla and download the cacert.pem file. This PrivacyEnhanced Mail (PEM) file contains a bundle of valid digital certificates that are used to verifythe authenticity of secure websites. The certificates are distributed by certificate authority (CA)companies such as GlobalSign and Verisign.Move the cacert.pem file to the bin subfolder that you unpacked in a previous step, for example,C:\curl\bin. Rename the file as curl-ca-bundle.crt.4.Also, the Microsoft Build Engine (MSBuild) must be able to locate the curl dll in the procedure thatfollows. Therefore, you should add the curl bin folder path to your Windows PATH environmentvariable, for example, set PATH %PATH%;C:\curl\bin. You must add this each time you open a newcommand prompt to build the SDK. Alternatively, you can set the environment variable globally in yourWindows system settings so that the setting is remembered.For alternative syntax required to build curl into your SDK, see Step 5 (Generate build files) in theBuilding the SDK from source procedure that follows.Building the SDK from sourceYou can build the SDK from source using command-line tools. Using this method, you can customizeyour SDK build. For information about available options, see CMake Parameters (p. 21). There arethree main steps. First, you build the files using CMake. Second, you use MSBuild to build the SDKbinaries that work with your operating system and build toolchain. Third, you install or copy the binariesinto the correct location on the development machine.To build the SDK from source1.2.Install CMake (minimum version 3.2; maximum version 3.21) and the relevant build tools for yourplatform. It is recommended to add cmake to your PATH. To check your version of CMake, open acommand prompt and run command cmake --versionIn a command prompt, navigate to a folder where you want to store the SDK.3.Get the latest source code.Version 1.9 simplifies dependencies by using git submodules to wrap external dependencies.Download or clone the SDK source from aws/aws-sdk-cpp on GitHub: Clone with Git: HTTPSgit clone --recurse-submodules https://github.com/aws/aws-sdk-cpp5

AWS SDK for C Developer GuideBuild on Windows Clone with Git: SSHgit clone --recurse-submodules git@github.com:aws/aws-sdk-cpp.git4.We recommend you store the generated build files outside of the SDK source directory. Create a newdirectory to store the build files in and navigate to that folder.mkdir sdk buildcd sdk build5.Generate the build files by running cmake. Specify on the cmake command line whether to build aDebug or Release version. Choose Debug throughout this procedure to run a debug configuration ofyour application code. Choose Release throughout this procedure to run a release configuration ofyour application code. Command syntax:{path to cmake if not in PATH} {path to source location of aws-sdk-cpp} DCMAKE BUILD TYPE [Debug Release]For more ways to modify the build output, see CMake Parameters (p. 21).To generate the build files, do one of the following: Generate build files (all AWS services): To build the entire SDK, run cmake, specifying whether tobuild a Debug or Release version. For example:"C:\Program Files (x86)\Microsoft Visual \Microsoft\CMake\CMake\bin\cmake.exe" ".\aws-sdk-cpp" DCMAKE BUILD TYPE Debug Generate build files (subset AWS services): To build only a particular service or servicespackage(s) for the SDK, add the CMake BUILD ONLY (p. 22) parameter. The following examplebuilds only the Amazon S3 service package:cmake .\aws-sdk-cpp -DCMAKE BUILD TYPE Debug -DBUILD ONLY "s3" Generate build files (with curl): After completing the curl prerequisites, three additional cmakecommand line options are required to include curl support in the SDK: FORCE CURL (p. 24),CURL INCLUDE DIR (p. 23), and CURL LIBRARY (p. 23). For example:cmake .\aws-sdk-cpp -DCMAKE BUILD TYPE Debug -DFORCE CURL ON -DCURL INCLUDE DIR 'C:/curl/include'-DCURL LIBRARY 'C:/curl/lib/libcurl.dll.a'NoteIf you get an error Failed to build third-party libraries, check your version of CMake byrunning cmake --version. You must use CMake minimum version 3.2, maximum version3.21.6.Build the SDK binaries. If you’re building the entire SDK, this step can take one hour or longer.Command syntax:{path to MSBuild if not in PATH} ALL BUILD.vcxproj -p:Configuration [Debug Release]"C:\Program Files (x86)\Microsoft Visual exe" ALL BUILD.vcxproj -p:Configuration Debug6

AWS SDK for C Developer GuideBuild on Linux/macOSNoteIf you encounter the error The code execution cannot proceed . dll not found. Reinstallingthe program may fix this problem.", retry the cmake command again.7.Open a command prompt with administrator privileges to install the SDK. This command installs theSDK in \Program Files (x86)\aws-cpp-sdk-all\. Command syntax:msbuild INSTALL.vcxproj -p:Configuration [Debug Release]msbuild INSTALL.vcxproj -p:Configuration DebugBuilding for Android on WindowsTo build for Android, add -DTARGET ARCH ANDROID to your cmake command line. The AWS SDKfor C includes a CMake toolchain file that includes what you need by referencing the appropriateenvironment variables (ANDROID NDK).To build the SDK for Android on Windows, you need to run cmake from a Visual Studio (2015 or later)developer command prompt. You’ll also need NMAKE NMAKEinstalled and the commands git andpatch in your path. If you have git installed on a Windows system, you’ll most likely find patch in asibling directory (./Git/usr/bin/). Once you’ve verified these requirements, your cmake commandline will change slightly to use NMAKE.cmake -G "NMake Makefiles" -DTARGET ARCH ANDROID other options .NMAKE builds serially. To build more quickly, we recommend you install JOM as an alternative to NMAKE,and then change the cmake invocation as follows:cmake -G "NMake Makefiles JOM" -DTARGET ARCH ANDROID other options .For an example application, see Setting up an Android application with AWS SDK for C Building the AWS SDK for C on Linux/macOSTo set up the AWS SDK for C , you can either build the SDK yourself directly from the source ordownload the libraries using a package manager.The SDK source is separated into individual packages by service. Installing the entire SDK can take up toan hour. Installing only the specific subset of services that your program uses decreases installation timeand also reduces size on disk. To choose which services to install, you need to know the package nameof each service your program uses. You can see the list of package directories at aws/aws-sdk-cpp onGitHub. The package name is the suffix of the directory name for the service.aws-sdk-cpp\aws-cpp-sdk- packageName aws-sdk-cpp\aws-cpp-sdk-s3# Repo directory name and packageName# Example: Package name is s3PrerequisitesYou need a minimum of 4 GB of RAM to build some of the larger AWS clients. The SDK might fail tobuild on Amazon EC2 instance types t2.micro, t2.small, and other small instance types due to insufficientmemory.7

AWS SDK for C Developer GuideBuild on Linux/macOSTo use the AWS SDK for C , you need one of the following: GNU Compiler Collection (GCC) 4.9 or later, or Clang 3.3 or later.Additional Requirements for Linux SystemsYou must have the header files (-dev packages) for libcurl, libopenssl, libuuid, zlib, and,optionally, libpulse for Amazon Polly support. You can find the packages by using your system’spackage manager.To install the packages on Debian/Ubuntu-based systems sudo apt-get install libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libpulse-devTo install the packages on Amazon Linux/Redhat/Fedora/CentOS-based systems sudo yum install libcurl-devel openssl-devel libuuid-devel pulseaudio-libs-develBuilding the SDK from SourceYou can build the SDK from source using command-line tools as an alternative to using vcpkg. Usingthis method, you can customize your SDK build. For information about available options, see CMakeParameters (p. 21).To build the SDK from source1.2.Install CMake (minimum version 3.2; maximum version 3.21) and the relevant build tools for yourplatform. It is recommended to add cmake to your PATH. To check your version of CMake, open acommand prompt and run command cmake --versionIn a command prompt, navigate to a folder where you want to store the SDK.3.Get the latest source code.Version 1.9 simplifies dependencies by using git submodules to wrap external dependencies.Download or clone the SDK source from aws/aws-sdk-cpp on GitHub: Clone with Git: HTTPSgit clone --recurse-submodules https://github.com/aws/aws-sdk-cpp Clone with Git: SSHgit clone --recurse-submodules git@github.com:aws/aws-sdk-cpp.git4.We recommend you store the generated build files outside of the SDK source directory. Create a newdirectory to store the build files in and navigate to that folder.mkdir sdk buildcd sdk build5.Generate the build files by running cmake. Specify on the cmake command line whether to build aDebug or Release version. Choose Debug throughout this procedure to run a debug configuration of8

AWS SDK for C Developer Guide"Hello S3" appyour application code. Choose Release throughout this procedure to run a release configuration ofyour application code. Command syntax:{path to cmake if not in PATH} {path to source location of aws-sdk-cpp} DCMAKE BUILD TYPE [Debug Release] -DCMAKE PREFIX PATH {path to install} DCMAKE INSTALL PREFIX {path to install}For more ways to modify the build output, see CMake Parameters (p. 21).To generate the build files, do one of the following: Generate build files (all AWS services): To build the entire SDK, run cmake, specifying whether tobuild a Debug or Release version. For example:cmake ./aws-sdk-cpp -DCMAKE BUILD TYPE Debug -DCMAKE PREFIX PATH /usr/local/ DCMAKE INSTALL PREFIX /usr/local/ Generate build files (subset AWS services): T

Build your application using the SDK 1. Write your own code to use the SDK or use a sample application, and add the AWSSDK package to your cmake file. 2. Use CMake to generate build files for your application. 3. Build your application. 4. Run your application. Then develop your own application using the SDK. "H e l o,S3! s tar p ic n (p. 8)

Related Documents:

AWS SDK for JavaScript AWS SDK for JavaScript code examples AWS SDK for .NET AWS SDK for .NET code examples AWS SDK for PHP AWS SDK for PHP code examples AWS SDK for Python (Boto3) AWS SDK for Python (Boto3) code examples AWS SDK for Ruby AWS SDK for Ruby co

AWS SDK for JavaScript Developer Guide for SDK Version 3 Maintenance and support for SDK major versions What is the AWS SDK for JavaScript? Welcome to the AWS SDK for JavaScript Developer Guide. This guide provides general information about setting up and configuring the AWS SDK for JavaScript. It also walks you through examples and tutorial

The AWS SDK for Ruby Developer Guide provides information about how to install, set up, and use the AWS SDK for Ruby to create Ruby applications that use AWS services. Getting Started with the AWS SDK for Ruby (p. 3) Additional Documentation and Resources For more resources for AWS SDK for Ruby developers, see the following:

4 AWS Training & Services AWS Essentials Training AWS Cloud Practitioner Essentials (CP-ESS) AWS Technical Essentials (AWSE) AWS Business Essentials (AWSBE) AWS Security Essentials (SEC-ESS) AWS System Architecture Training Architecting on AWS (AWSA) Advanced Architecting on AWS (AWSAA) Architecting on AWS - Accelerator (ARCH-AX) AWS Development Training

LÄS NOGGRANT FÖLJANDE VILLKOR FÖR APPLE DEVELOPER PROGRAM LICENCE . Apple Developer Program License Agreement Syfte Du vill använda Apple-mjukvara (enligt definitionen nedan) för att utveckla en eller flera Applikationer (enligt definitionen nedan) för Apple-märkta produkter. . Applikationer som utvecklas för iOS-produkter, Apple .

ANDROID SDK INSTALLATION . Receive the SDK . After receiving information on how to retrieve the ZIP File containing the SDK, use the following steps on to install the SDK properly. Install Static Library & Header . To install the Barometric SDK, add the files included in the zip file to the listed locations below. .ZIP FILES FILE LOCATION

AWS Directory Amazon Aurora R5 instance Service AWS Server Migration Service AWS Snowball AWS Deep Amazon GameLift Learning AMIs AWS CodeBuild AWS CodeDeploy AWS Database Migration Service Amazon Polly 26 26 20 40 12 0 5 10 15 20 25 30 35 40 45 2018 Q1 2018 Q2 2018 Q3 2018 Q4 2019 Q1 New Services& Features on AWS

AWS instances with Nessus while in development and operations, before publishing to AWS users. Tenable Network Security offers two products on the AWS environment: Nessus for AWS is a Nessus Enterprise instance already available in the AWS Marketplace. Tenable Nessus for AWS provides pre-authorized scanning in the AWS cloud via AWS instance ID.