Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build AWS SDK for C++ IoT example in Docker container #3076

Closed
lopezdp opened this issue Aug 10, 2024 · 3 comments
Closed

Unable to build AWS SDK for C++ IoT example in Docker container #3076

lopezdp opened this issue Aug 10, 2024 · 3 comments
Labels
response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@lopezdp
Copy link

lopezdp commented Aug 10, 2024

Describe the bug

I've made several attempts to build an AWS SDK for C++ IoT example in a Docker container. Here are the last three approaches I've tried:

  1. I tried to use the AWS IoT Device SDK for C++ v2, but encountered issues with finding the necessary packages.
  2. I switched to the AWS SDK for C++ and attempted to build only the IoT component, but faced problems with missing ZLIB libraries.
  3. I addressed the ZLIB issue but ran into problems with missing IoT-specific headers.

In each iteration, I've updated the Dockerfile and CMakeLists.txt files to address the errors encountered.

Bug Description:

When attempting to build an AWS SDK for C++ IoT example in a Docker container, the compilation fails due to missing IoT-specific headers.

Expected Behavior

The Docker build should complete successfully, allowing the creation of an IoT publisher application using the AWS SDK for C++.

Current Behavior

/app/main.cpp:3:10: fatal error: aws/iot/model/PublishRequest.h: No such file or directory
    3 | #include <aws/iot/model/PublishRequest.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Reproduction Steps

  1. Create a Dockerfile with the following content:
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=America/Los_Angeles

RUN apt-get update && apt-get install -y \
    git \
    cmake \
    g++ \
    libcurl4-openssl-dev \
    libssl-dev \
    zlib1g-dev \
    ninja-build \
    python3 \
    python3-pip

WORKDIR /app

RUN git clone --recursive https://github.com/aws/aws-sdk-cpp.git
WORKDIR /app/aws-sdk-cpp
RUN mkdir build && cd build && \
    cmake .. -DBUILD_ONLY="iot" \
             -DCMAKE_BUILD_TYPE=Release \
             -DBUILD_SHARED_LIBS=OFF \
             -DENABLE_TESTING=OFF \
             -DCMAKE_POSITION_INDEPENDENT_CODE=ON && \
    make && make install

WORKDIR /app
COPY . .

RUN mkdir build && cd build && \
    cmake .. && \
    make

CMD ["./build/iot_publisher"]
  1. Create a CMakeLists.txt file with the following content:
cmake_minimum_required(VERSION 3.10)
project(iot_publisher)

set(CMAKE_CXX_STANDARD 11)

find_package(AWSSDK REQUIRED COMPONENTS iot)
find_package(ZLIB REQUIRED)

add_executable(iot_publisher main.cpp)
target_link_libraries(iot_publisher ${AWSSDK_LINK_LIBRARIES} ZLIB::ZLIB)
  1. Create a main.cpp file with the IoT publisher code (including the problematic header).
#include <aws/core/Aws.h>
#include <aws/iot/IoTClient.h>
#include <aws/iot/model/PublishRequest.h>
#include <iostream>

int main() {
    Aws::SDKOptions options;
    Aws::InitAPI(options);

    {
        Aws::Client::ClientConfiguration clientConfig;
        // Use the provided endpoint
        clientConfig.endpointOverride = "***8***-ats.iot.us-east-1.amazonaws.com";
        clientConfig.scheme = Aws::Http::Scheme::HTTPS;
        clientConfig.caFile = "certs/AmazonRootCA1.pem";
        clientConfig.clientCertificate = "certs/***8***-certificate.pem.crt"; // masked/hidden
        clientConfig.privateKey = "certs/***8***-private.pem.key";

        Aws::IoT::IoTClient iotClient(clientConfig);

        Aws::IoT::Model::PublishRequest publishRequest;
        publishRequest.SetTopic("iot/test_topic/tst-1");
        publishRequest.SetPayload(Aws::Utils::ByteBuffer((unsigned char*)"[AUDIT] - LF Automation Team", 28));

        auto publishOutcome = iotClient.Publish(publishRequest);

        if (publishOutcome.IsSuccess()) {
            std::cout << "Message published successfully to " << clientConfig.endpointOverride << std::endl;
        } else {
            std::cout << "Failed to publish message: " << publishOutcome.GetError().GetMessage() << std::endl;
        }
    }

    Aws::ShutdownAPI(options);
    return 0;
}
  1. Run the Docker build command:

docker build -t iot-publisher .

Possible Solution

The issue might be related to how the IoT component of the AWS SDK for C++ is built or installed. We may need to adjust the build flags or include paths to ensure all necessary headers are available.

Additional Information/Context:

Using AWS IoT Core endpoint: hidden-ats.iot.us-east-1.amazonaws.com

Using IoT Core topic: iot/Test_Topic/tst-1 (also hidden)

Certificate files are available in the project directory

  1. Potential fix to test:

Have tried an approach using the AWS IoT Device SDK for C++ v2 instead of the full AWS SDK for C++. Doesnt work either...

Additional Information/Context

No response

AWS CPP SDK version used

1.11.381

Compiler and Version used

gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Operating System and version

Ubuntu 20.04

@lopezdp lopezdp added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 10, 2024
@DmitriyMusatkin
Copy link
Contributor

IoT device C++ sdk and C++ sdk are different things.
Device SDKs implement mqtt protocol for publishing/subscribing to events. While regular sdks only expose functions to communicate with http side of the service.

So its expected that publish request headers are missing in C++ sdk and that IoT device example will not work.
What does not work with iot device sdk? You might have more luck filing issue with them directly https://github.com/aws/aws-iot-device-sdk-cpp-v2

@DmitriyMusatkin DmitriyMusatkin added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 11, 2024
@lopezdp
Copy link
Author

lopezdp commented Aug 12, 2024

@DmitriyMusatkin youre right - I tried multiple approaches and ultimately put the ticket in the wrong place. ill come back to this and set up Mqtt ticket on other repo

@lopezdp lopezdp closed this as completed Aug 12, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

2 participants