Unverified Commit df7f4d02 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Fix the SDK canary (#2946)

The SDK canary was:
- Failing, but marking that failure as a pass.
- Failing on string compare on the Transcribe Streaming test.
- Failing on permissions with the EC2 test.

This PR fixes these issues.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 63d880d6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ impl CanaryEnv {
        // Amazon Transcribe starts returning different output for the same audio.
        let expected_transcribe_result = env::var("CANARY_EXPECTED_TRANSCRIBE_RESULT")
            .unwrap_or_else(|_| {
                "Good day to you transcribe. This is Polly talking to you from the Rust ST K."
                "Good day to you transcribe. This is Polly talking to you from the Rust S. D. K."
                    .to_string()
            });

+271 −285

File changed.

Preview size limit exceeded, changes collapsed.

+4 −4
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@ publish = false
[dependencies]
anyhow = "1"
async-trait = "0.1.56"
aws-config = "0.55.3"
aws-sdk-cloudwatch = "0.28.0"
aws-sdk-lambda = "0.28.0"
aws-sdk-s3 = "0.28.0"
aws-config = "0.56.0"
aws-sdk-cloudwatch = "0.29.0"
aws-sdk-lambda = "0.29.0"
aws-sdk-s3 = "0.29.0"
base64 = "0.13"
clap = { version = "3.2.17", features = ["derive"] }
hex = "0.4.3"
+35 −1
Original line number Diff line number Diff line
@@ -27,13 +27,14 @@ use serde::Deserialize;
use smithy_rs_tool_common::git::{find_git_repository_root, Git, GitCLI};
use smithy_rs_tool_common::macros::here;
use smithy_rs_tool_common::release_tag::ReleaseTag;
use tracing::info;
use tracing::{error, info};

use crate::build_bundle::BuildBundleArgs;

use aws_sdk_cloudwatch as cloudwatch;
use aws_sdk_lambda as lambda;
use aws_sdk_s3 as s3;
use std::collections::HashMap;

lazy_static::lazy_static! {
    // Occasionally, a breaking change introduced in smithy-rs will cause the canary to fail
@@ -170,6 +171,9 @@ pub async fn run(opt: RunArgs) -> Result<()> {
    let start_time = SystemTime::now();
    let config = aws_config::load_from_env().await;
    let result = run_canary(&options, &config).await;
    if let Err(err) = &result {
        error!("Canary invocation failed: {err:?}",);
    }

    let mut metrics = vec![
        (
@@ -422,6 +426,36 @@ async fn invoke_lambda(lambda_client: lambda::Client, bundle_name: &str) -> Resu
                .unwrap_or("<no error given>")
        );
    }
    if let Some(payload) = response.payload {
        // Example payload:
        // {
        //  "failures": {
        //    "ec2_paginator": "service error\n\nCaused by:\n    0: unhandled error\n    1: unhandled error\n    2: Error { code: \"UnauthorizedOperation\", message: \"You are not authorized to perform this operation.\", aws_request_id: \"0adcd3f5-73f3-45a2-bd2e-09e4172b65f1\" }",
        //    "transcribe_canary": "Transcription from Transcribe doesn't look right:\nExpected: `Good day to you transcribe. This is Polly talking to you from the Rust ST K.`\nActual:   `Good day to you transcribe. This is Polly talking to you from the Rust S. D. K.`\n"
        //  },
        //  "result": "failure"
        //}
        #[derive(serde::Deserialize)]
        struct Payload {
            failures: Option<HashMap<String, String>>,
            result: String,
        }
        let payload: Payload = serde_json::from_slice(payload.as_ref())?;
        if payload.result == "failure"
            || !payload
                .failures
                .as_ref()
                .map(|m| m.is_empty())
                .unwrap_or(true)
        {
            if let Some(failures) = &payload.failures {
                for (service, message) in failures {
                    error!("{service} failed:\n{message}\n");
                }
            }
            bail!("The canary failed.");
        }
    }
    Ok(())
}

+9 −0
Original line number Diff line number Diff line
@@ -152,6 +152,15 @@ export class CanaryStack extends Stack {
            }),
        );

        // Allow canaries to call EC2
        this.lambdaExecutionRole.addToPolicy(
            new PolicyStatement({
                actions: ["ec2:DescribeSpotPriceHistory", "ec2:DescribeVpcs"],
                effect: Effect.ALLOW,
                resources: ["*"],
            }),
        );

        // Allow the OIDC role to pass the Lambda execution role to Lambda
        if (this.awsSdkRustOidcRole) {
            this.awsSdkRustOidcRole.oidcRole.addToPolicy(
Loading