Skip to content

Rust version of the CloudWatchAlarmSNSPayload struct/type #793

Closed
@dacbd

Description

@dacbd

ref from go: https://github.com/aws/aws-lambda-go/blob/3a93ed1e265b5e368f0d20c3a2b8395d2c9f787d/events/sns.go#L34C6-L45

Maybe I'm not finding the correct struct somewhere in the SDK, but I have many cloud watch metrics alarms going to an sns topic. one of the subscribers to the topic is an lambda function.

Example:

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .with_target(false)
        .without_time()
        .init();

    run(service_fn(lambda_handler)).await
}

async fn lambda_handler(event: LambdaEvent<SnsEvent>) -> Result<(), Error> {
    info!("received events: {:?}", event.payload.records.len());
    for event in event.payload.records {
        process_record(&event)?;
    }
    Ok(())
}

fn process_record(record: &SnsRecord) -> Result<(), Error> {
    info!("processing record");
    let message = &record.sns;
    info!(message = ?message);
    /*
    I would like something to the effect of:
    let payload: CloudWatchAlarmSNSPayload = serde_json::from_str(message.message)
    */
    Ok(())
}

Or really just: SnsMessageObj<CloudWatchAlarmSNSPayload>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions