Questions tagged with AWS Command Line Interface

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Failure in Cloudformation template [ CommandRunenr] while running CLI command for Cloudtrail

Hi Guys, I am trying to run CLI command to update a CloudTrail but stack is getting failed. Requirement is to apply advanced data events to existing CloudTrail. Please find below details of CF template: 1. CF template AWSTemplateFormatVersion: 2010-09-09 Resources: UpdateTrail: Type: AWSUtility::CloudFormation::CommandRunner Properties: Role: ec2-role-name SubnetId: subnet-XXXXXXXXX LogGroup: log-group-name Command: aws cloudtrail put-event-selectors --trail-name XXXX --region XXXX \ --advanced-event-selectors.... 2. Error Resource handler returned message: "Either the command failed to execute, the value written to /command-output.txt was invalid or the Subnet specified did not have internet access. The value written to /command-output.txt must be a non-empty single word value without quotation marks. Check cloud-init.log in the LogGroup specified for more information." 3. CLI command aws cloudtrail put-event-selectors --trail-name XXXX --region XXXX --advanced-event-selectors '[ { "Name": "S3EventSelector", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::S3::Object"] }, { "Field": "eventName", "Equals": ["PutObject","DeleteObject"] }, { "Field": "resources.ARN", "StartsWith": ["arn:aws:s3:::XX","arn:aws:s3:::XX"] } ] } ]' Note : Command runs successfully in CLI. pre-requisites for commandRunner is installed. Also, Subnet specified does have internet access. I sense, it might be the issue with command format or may be something else. Any assistance would be appreciated. Thanks
1
answers
0
votes
45
views
Pradnya
asked 14 days ago

How to get ip addresses of apigateway vpce using cdk?

**Background context / End goal:** I am trying to use cdk to create a target group that consists of the ip addresses that are associated with a vpc endpoint (for apigateway) as per this [AWS blog.][1] Ideally, I would like to be able to just lookup the associated ips using just the fact that the vpce is for the service of apigateway OR potentially using the vpce id. **Problem** I cannot find a way to get the network interface ids & ip addresses for the vpc endpoint. **Attempts** 1. I tried to use the cdk [InterfaceVpcEndpoint construct][2] static method using the fromInterfaceVpcEndpointAttributes (filtering by service). It did return the desired vpce, but unfortunately it returns [in the format of IInterfaceVpcEndpoint][3] which does not have the vpceNetworkInterfaceIds attribute that the InterfaceVpcEndpoint construct has 2. I was able to use [AwsCustomResource][4] (after consulting a stack overflow post that referenced [this example][5]) to look up the ip addresses for a given array of vpce network interface ids: ``` const vpceNetworkInterfaceIds = =['eniId1', 'eniId2']; const getEniIps = new AwsCustomResource(scope, `GetEndpointIps`, { onUpdate: { service: "EC2", action: "describeNetworkInterfaces", parameters: { NetworkInterfaceIds: vpceNetworkInterfaceIds }, physicalResourceId: PhysicalResourceId.of(Date.now().toString()) }, policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }), }); const privateIpAddresses: string[] = []; for(let i = 0; i< vpceNetworkInterfaceIds.length; i++){ const privateIpAddress: string = getNetworkInterfaceIpAddresses.getResponseField(`NetworkInterfaces.${i}.PrivateIpAddress`).toString(); privateIpAddresses.push(privateIpAddress); } return privateIpAddresses; } ``` 3. I tried to make a similar sdk call ([describeVpcEndpoints][6]), but then I encountered issues retrieving the array of NetworkInterfaceIds. ``` const getNetworkInterfaceIpAddresses = new AwsCustomResource(scope, `GetVpceNetworkInterfaceIds`, { onUpdate: { service: "EC2", action: "describeVpcEndpoints", parameters: { Filters: [ { Name: "service-name", Values: ["com.amazonaws.us-east-1.execute-api"] } ] }, physicalResourceId: PhysicalResourceId.of(Date.now().toString()) }, policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }), }); return getNetworkInterfaceIpAddresses.getResponseFieldReference(`VpcEndpoints.0.NetworkInterfaceIds`).toJSON(); ``` I tried variations of using the [Reference][7] methods of toJson, toString, Token.asXXX but was not able to figure out how to get the array of values from this custom resource. One of the errors that I got was "Vendor response doesn't contain VpcEndpoints.0.NetworkInterfaceIds key in object ....." but when I made the describeVpcEndpoints call via cli, I can definitely see that there is a VpcEndpoints.0.NetworkInterfaceIds value that should be populated. **Questions** 1. How can you get an array from the sdk call of a aws custom resource? 2. How can you debug cdk aws custom resources that make sdk calls? Logging locally only yields the tokens which is not helpful. 3. Is there a more straight forward way to get the vpceNetworkInterfaceIds of a given vpce? 4. Is there a more straight forward way to get the ip addresses for a given vpce? [1]: https://aws.amazon.com/blogs/networking-and-content-delivery/accessing-an-aws-api-gateway-via-static-ip-addresses-provided-by-aws-global-accelerator/ [2]: https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-ec2.InterfaceVpcEndpoint.html#vpcendpointnetworkinterfaceids [3]: https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-ec2.IInterfaceVpcEndpoint.html [4]: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.custom_resources.AwsCustomResource.html#getwbrresponsewbrfielddatapath [5]: https://github.com/taimos/cdk-constructs/blob/master/lib/serverless/internal-rest-api.ts#L117 [6]: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeVpcEndpoints-property [7]: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Reference.html#towbrstringwbrlist
1
answers
0
votes
65
views
asked 16 days ago

Error in lexClient->StartConversationAsync

I am currently trying to establish a stream connection between my AWSClient and a Lex Bot. I am getting the following error: ``` aws-sdk-cpp/aws-cpp-sdk-core/source/auth/signer-provider/DefaultAuthSignerProvider.cpp:48: virtual std::shared_ptr<Aws::Client::AWSAuthSigner> Aws::Auth::DefaultAuthSignerProvider::GetSigner(const String&) const: Assertion `false' failed. Aborted (core dumped) ``` when the code run through the following line: ``` lexClient->StartConversationAsync(LexRequest, OnStreamReady, OnResponseCallback, nullptr); starting.WaitOne(); ``` the entire .cpp follows: ``` #include <aws/core/Aws.h> #include <aws/core/client/AsyncCallerContext.h> #include <aws/core/utils/Outcome.h> #include <aws/core/auth/AWSCredentialsProvider.h> #include <aws/lexv2-runtime/LexRuntimeV2Client.h> #include <aws/lexv2-runtime/model/AudioInputEvent.h> #include <aws/lexv2-runtime/model/RecognizeUtteranceRequest.h> #include <aws/lexv2-runtime/model/RecognizeUtteranceResult.h> #include <aws/lexv2-runtime/model/StartConversationHandler.h> #include <aws/lexv2-runtime/model/StartConversationRequest.h> #include <aws/lexv2-runtime/model/StartConversationRequestEventStream.h> #include <aws/lex/LexRuntimeServiceClient.h> #include <aws/lex/LexRuntimeServiceRequest.h> #include <aws/lex/model/PostContentRequest.h> #include <aws/lex/model/PostContentResult.h> #include <iterator> #include <fstream> #include <chrono> #include <unistd.h> using namespace Aws::LexRuntimeV2; int SessionCount = 0; int main(int argc, char* argv[]) { std::string lexKey, lexSecret; std::string botId, botAliasId, localeId, sessionId, regionId; // bot credentials botId = "_"; botAliasId = "_"; lexKey = "_"; lexSecret = "_"; localeId = "en_US"; // starting api Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; Aws::InitAPI(options); Aws::Client::ClientConfiguration config; config.region = "us-east-1"; // creating a lex client auto lexClient = Aws::MakeUnique<LexRuntimeV2Client>("MyClient", Aws::Auth::AWSCredentials(lexKey.c_str(), lexSecret.c_str()), config); Model::StartConversationRequest LexRequest; Model::StartConversationHandler requestHandler; requestHandler.SetTranscriptEventCallback([](const Model::TranscriptEvent& ev) { std::cout << ev.GetTranscript() << std::endl; }); requestHandler.SetOnErrorCallback([](const Aws::Client::AWSError<LexRuntimeV2Errors>& error) { std::cout << "Request handler: " << error.GetMessage() << std::endl; }); LexRequest.WithLocaleId(localeId).WithBotId(botId.c_str()).WithBotAliasId(botAliasId.c_str()).WithSessionId("Blah") .WithConversationMode(Model::ConversationMode::AUDIO).WithEventStreamHandler(requestHandler); Aws::Utils::Threading::Semaphore signaling(0 /*initialCount*/, 1 /*maxCount*/); auto OnResponseCallback = [&signaling](const LexRuntimeV2Client*,const Model::StartConversationRequest&, const Model::StartConversationOutcome& outcome, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&) { std::cout << "Response handler: " << outcome.GetError().GetMessage(); signaling.Release(); }; Model::StartConversationRequestEventStream* pStream = nullptr; Aws::Utils::Threading::Semaphore starting(0 /*initialCount*/, 1 /*maxCount*/); auto OnStreamReady = [&starting,&pStream](Model::StartConversationRequestEventStream& stream) { pStream = &stream; pStream->SetSignatureSeed("blah"); starting.Release(); }; lexClient->StartConversationAsync(LexRequest, OnStreamReady, OnResponseCallback, nullptr); starting.WaitOne(); std::ifstream audioFile(argv[1], std::ios_base::binary); if (!audioFile) { std::cout << "Cannot open audio file " << argv[2] << std::endl; return 0; } if (audioFile) { std:: cout << "Audio file is open: "<< std::endl; } while (!audioFile.eof()) { unsigned char buf[320 + 1]; audioFile.read((char*)buf, 320); Aws::Utils::ByteBuffer bytes(buf, audioFile.gcount()); Model::AudioInputEvent input; auto millisec_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock().now().time_since_epoch()).count(); input.SetClientTimestampMillis(millisec_since_epoch); input.SetAudioChunk(bytes); input.SetContentType("audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false"); pStream->WriteAudioInputEvent(input); // o erro está aqui (quando comento o StartConversation) sleep(20); } signaling.WaitOne(); // prevent the application from exiting until we're done Aws::ShutdownAPI(options); } //g++ -o main main.cpp -laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-cpp-sdk-lex -laws-cpp-sdk-lex-models -laws-cpp-sdk-lexv2-models -laws-cpp-sdk-lexv2-runtime ``` I have no idea why this is happening, and without this command i obviously can't publish events to lex, since the connection does not have started
0
answers
0
votes
23
views
asked 23 days ago