Related
What I am trying to achieve :- When a codebuild stage( action) is is successful, I want to send a notification to slack. The real catch is in the message I want to send the codebuild build logs console link.
In my current workflow when codebuild build is successful it sends default event to sns -> which triggers lambda -> slack
I am pretty sure there must be a way to receive codebuild build logs console link. Since URL for console link for every build is dynamic it cant be set static in my opinion.
Also:- Since this is not possible in default event, I was thinking to create a custom event in lambda ( after getting triggered from sns ) and add the console link and then pass on to slack.Is this the right approach?
You can get log group link in two way.
First one is on Codebuild page you can create "Create notification rule" under "Notify" menu. Then you need to select only "Succeeded" on Build State of "Events that trigger notifications" then only two option to forward this message SNS or AWS Chatbot.
When you choose SNS, attach a Lambda as subscription to this SNS.On lambda function you will get a message like
message = json.loads(event.Records[0].SNS.Message) then get log from message message.detail.additional-information.logs.deep-link
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:us-east-1: 3595xxx02761:codestar-notifications-test: 3648ad36-735e-4ce7-83ad-f5340d503c5d",
"Sns": {
"Type": "Notification",
"MessageId": "df6e2eed-651e-5e21-b24b-72d5c7cdb684",
"TopicArn": "arn:aws:sns:us-east-1: 3595xxx02761:codestar-notifications-test",
"Subject": None,
"Message": "{"account": "3595xxx02761",
"detailType": "CodeBuild Build State Change",
"region": "us-east-1",
"source": "aws.codebuild",
"time": "2023-01-11T11:42:06Z",
"notificationRuleArn": "arn:aws:codestar-notifications:us-east-1:3595xxx02761:notificationrule/e0b422a57a890c96aad913a2d9b0ca0d2f845223",
"detail": {
"build-status": "SUCCEEDED",
"project-name": "test-build",
"build-id": "arn:aws:codebuild:us-east-1:3595xxx02761:build/test-build:88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2",
"additional-information": {
"cache": {
"type": "NO_CACHE"
},
"build-number": 1.0,
"timeout-in-minutes": 60.0,
"build-complete": true,
"initiator": "root",
"build-start-time": "Jan 11, 2023 11:41:22 AM",
"source": {
"git-clone-depth": 1.0,
"type": "NO_SOURCE"
},
"artifact": {
"location": ""
},
"environment": {
"image": "aws/codebuild/amazonlinux2-x86_64-standard:4.0",
"privileged-mode": false,
"image-pull-credentials-type": "CODEBUILD",
"compute-type": "BUILD_GENERAL1_SMALL",
"type": "LINUX_CONTAINER",
"environment-variables": []
},
"logs": {
"group-name": "/aws/codebuild/test-build",
"stream-name": "88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2",
"deep-link": "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logEvent:group=/aws/codebuild/test-build;stream=88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2"
},
"phases": [
{
"phase-context": [],
"start-time": "Jan 11, 2023 11:41:22 AM",
"end-time": "Jan 11, 2023 11:41:22 AM",
"duration-in-seconds": 0.0,
"phase-type": "SUBMITTED",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Jan 11, 2023 11:41:22 AM",
"end-time": "Jan 11, 2023 11:41:24 AM",
"duration-in-seconds": 1.0,
"phase-type": "QUEUED",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:41:24 AM",
"end-time": "Jan 11, 2023 11:41:57 AM",
"duration-in-seconds": 33.0,
"phase-type": "PROVISIONING",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:41:57 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 2.0,
"phase-type": "DOWNLOAD_SOURCE",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 0.0,
"phase-type": "INSTALL",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 0.0,
"phase-type": "PRE_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 0.0,
"phase-type": "BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 0.0,
"phase-type": "POST_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:00 AM",
"duration-in-seconds": 0.0,
"phase-type": "UPLOAD_ARTIFACTS",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
": "
],
"start-time": "Jan 11, 2023 11:42:00 AM",
"end-time": "Jan 11, 2023 11:42:04 AM",
"duration-in-seconds": 4.0,
"phase-type": "FINALIZING",
"phase-status": "SUCCEEDED"
},
{
"start-time": "Jan 11, 2023 11:42:04 AM",
"phase-type": "COMPLETED"
}
],
"queued-timeout-in-minutes": 480.0
},
"current-phase": "COMPLETED",
"current-phase-context": "[: ]",
"version": "1"
},
"resources": [
"arn:aws:codebuild:us-east-1:3595xxx02761:build/test-build:88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2"
],
"additionalAttributes": {}
}", "Timestamp": "2023-01-11T11: 42: 11.284Z", "SignatureVersion": "1", "Signature": "QyI4CAlszBYE8MJLy+Wwxpn/Ie4kFYigaaRzPEAz4v6vFDE7x7TjaG7yWSiLNGFnBXLpg6Cl3/B70eTLJKmNv/5adXOsDz0Pw53iAcXumLsgtSuPoCpG3zISPvgR1nLBfZia7fv0w02C6d9LrjQq5v8jRZi/GJUt5frigL4Tfq3Q+wAFkmjl31GfxjcSTc0X7ujO1t+/qRIcVaa+XXOhLcDTWG9Q0qWMh0jyf5/126d3CUSRhlM6v9OzqZ4w5a/qEkq+XMaH2ElDdF9rEN+D+GayqltA4hkxwERsbvNyHmG7LBthWChezxfohJ88/O3nIvCsyv1IX9MNgyeWcOxHnA==", "SigningCertUrl": "https: //sns.us-east-1.amazonaws.com/SimpleNotificationService-56e67fcb41f6fec09b0196692625d385.pem", "UnsubscribeUrl": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:3595xxx02761:codestar-notifications-test:3648ad36-735e-4ce7-83ad-f5340d503c5d", "MessageAttributes": {}}}]}
Other option using EventBridge Rule, using an event pattern like
{
"source": ["aws.codebuild"],
"detail-type": ["CodeBuild Build State Change"],
"detail": {
"build-status": ["SUCCEEDED"]
}
}
your answer on the event field event.detail.additional-information.logs.deep-link is link for log stream.
{
"version": "0",
"id": "1bdc2d34-2b5a-4de9-8738-bd38ef2de265",
"detail-type": "CodeBuild Build State Change",
"source": "aws.codebuild",
"account": "3595xxx02761",
"time": "2023-01-11T11:42:06Z",
"region": "us-east-1",
"resources": ["arn:aws:codebuild:us-east-1:3595xxx02761:build/test-build:88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2"],
"detail": {
"build-status": "SUCCEEDED",
"project-name": "test-build",
"build-id": "arn:aws:codebuild:us-east-1:3595xxx02761:build/test-build:88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2",
"additional-information": {
"cache": {"type": "NO_CACHE"},
"build-number": 1.0,
"timeout-in-minutes": 60.0,
"build-complete": True,
"initiator": "root",
"build-start-time": "Jan 11, 2023 11:41:22 AM",
"source": {"buildspec": "version: 0.2\n\nphases:\n build:\n commands:\n - echo "Hello world"\n", "git-clone-depth": 1.0, "type": "NO_SOURCE"},
"artifact": {"location": ""},
"environment": {"image": "aws/codebuild/amazonlinux2-x86_64-standard:4.0", "privileged-mode": False, "image-pull-credentials-type": "CODEBUILD", "compute-type": "BUILD_GENERAL1_SMALL", "type": "LINUX_CONTAINER", "environment-variables": []},
"logs": {"group-name": "/aws/codebuild/test-build", "stream-name": "88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2", "deep-link": "https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logEvent:group=/aws/codebuild/test-build;stream=88cfdd6f-0028-4bd6-ae43-ce44fcf5bbc2"},
"phases": [{"phase-context": [], "start-time": "Jan 11, 2023 11:41:22 AM", "end-time": "Jan 11, 2023 11:41:22 AM", "duration-in-seconds": 0.0, "phase-type": "SUBMITTED", "phase-status": "SUCCEEDED"}, {"phase-context": [], "start-time": "Jan 11, 2023 11:41:22 AM", "end-time": "Jan 11, 2023 11:41:24 AM", "duration-in-seconds": 1.0, "phase-type": "QUEUED", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:41:24 AM", "end-time": "Jan 11, 2023 11:41:57 AM", "duration-in-seconds": 33.0, "phase-type": "PROVISIONING", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:41:57 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 2.0, "phase-type": "DOWNLOAD_SOURCE", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 0.0, "phase-type": "INSTALL", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 0.0, "phase-type": "PRE_BUILD", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 0.0, "phase-type": "BUILD", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 0.0, "phase-type": "POST_BUILD", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:00 AM", "duration-in-seconds": 0.0, "phase-type": "UPLOAD_ARTIFACTS", "phase-status": "SUCCEEDED"}, {"phase-context": [": "], "start-time": "Jan 11, 2023 11:42:00 AM", "end-time": "Jan 11, 2023 11:42:04 AM", "duration-in-seconds": 4.0, "phase-type": "FINALIZING", "phase-status": "SUCCEEDED"}, {"start-time": "Jan 11, 2023 11:42:04 AM", "phase-type": "COMPLETED"}],
"queued-timeout-in-minutes": 480.0
},
"current-phase": "COMPLETED",
"current-phase-context": "[: ]",
"version": "1"
}
}
We're using CodeBuild and have implemented our own email build notification system (as seems to be required currently).
We use the same CodeBuild project to build all of our branches for the same Bitbucket repository and we use an EventBridge rule that triggers if that CodeBuild project fails. It then calls a Lambda function to issue a notification via a SNS topic.
We can get some basic information in the event passed to Lambda from EventBridge, such as the build number, project and status. But we need to include the branch the build was triggered for since it is confusing when these emails arrive and it's unclear what branch the error was on. Additionally, having the author of the commit triggering the build would be helpful to just email them rather than the more general notification we're currently doing.
Unfortunately neither the branch nor author seem to be in the event. Is there a way to include them or fetch them?
Our EventBridge event pattern is
{
"detail": {
"build-status": ["FAILED"],
"project-name": ["api"]
},
"detail-type": ["CodeBuild Build State Change"],
"source": ["aws.codebuild"]
}
Our Lambda is
const AWS = require("aws-sdk");
const snsTopicArn = process.env.TOPIC_ARN;
exports.handler = (event, context, callback) => {
const status = event.detail["build-status"];
const project = event.detail["project-name"];
const buildLabel = event.detail["additional-information"]["build-number"];
const account = event.account;
const region = event.region;
// determine the link to the build
const buildFullId = event.detail["build-id"];
const buildIdParts = buildFullId.split(":");
const buildId = buildIdParts[buildIdParts.length - 1];
const buildLink = `https://${region}.console.aws.amazon.com/codesuite/codebuild/${account}/projects/${project}/build/${project}%3A${buildId}/?region=${region}`;
const subject = `${project} build ${buildLabel} ${status}`;
const message = `${subject}\n\n${buildLink}`;
const sns = new AWS.SNS();
sns.publish(
{
TopicArn: snsTopicArn,
Message: message,
Subject: subject,
},
function (error, data) {
if (error) console.log(error, error.stack);
callback(error, data);
}
);
};
And we're getting events like this passed to our Lambda:
{
"version": "0",
"id": "...",
"detail-type": "CodeBuild Build State Change",
"source": "aws.codebuild",
"account": "...",
"time": "2022-08-24T09:01:14Z",
"region": "eu-west-2",
"resources": [
"arn:aws:codebuild:eu-west-2:...:build/demo-release-deployment:..."
],
"detail": {
"build-status": "FAILED",
"project-name": "demo-release-deployment",
"build-id": "arn:aws:codebuild:eu-west-2:...:build/demo-release-deployment:...",
"additional-information": {
"cache": {
"type": "NO_CACHE"
},
"build-number": 18,
"timeout-in-minutes": 10,
"build-complete": true,
"initiator": "...",
"build-start-time": "Aug 24, 2022 8:57:39 AM",
"source": {
"report-build-status": true,
"buildspec": "",
"location": "...#bitbucket.org/.../build-test.git>https://...#bitbucket.org/.../build-test.git",
"git-clone-depth": 1,
"type": "BITBUCKET",
"git-submodules-config": {
"fetch-submodules": true
}
},
"artifact": {
"location": ""
},
"environment": {
"image": "aws/codebuild/amazonlinux2-x86_64-standard:4.0",
"privileged-mode": false,
"image-pull-credentials-type": "CODEBUILD",
"compute-type": "BUILD_GENERAL1_SMALL",
"type": "LINUX_CONTAINER",
"environment-variables": []
},
"logs": {
"group-name": "demo-deployment",
"stream-name": "demo-deployment/...",
"deep-link": "https://console.aws.amazon.com/cloudwatch/home?region=eu-west-2#logEvent:group=demo-deployment;stream=demo-deployment/..."
},
"phases": [
{
"phase-context": [],
"start-time": "Aug 24, 2022 8:57:39 AM",
"end-time": "Aug 24, 2022 8:57:39 AM",
"duration-in-seconds": 0,
"phase-type": "SUBMITTED",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Aug 24, 2022 8:57:39 AM",
"end-time": "Aug 24, 2022 8:58:51 AM",
"duration-in-seconds": 72,
"phase-type": "QUEUED",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 8:58:51 AM",
"end-time": "Aug 24, 2022 9:00:59 AM",
"duration-in-seconds": 127,
"phase-type": "PROVISIONING",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:00:59 AM",
"end-time": "Aug 24, 2022 9:01:06 AM",
"duration-in-seconds": 6,
"phase-type": "DOWNLOAD_SOURCE",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:01:06 AM",
"end-time": "Aug 24, 2022 9:01:06 AM",
"duration-in-seconds": 0,
"phase-type": "INSTALL",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:01:06 AM",
"end-time": "Aug 24, 2022 9:01:06 AM",
"duration-in-seconds": 0,
"phase-type": "PRE_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
"COMMAND_EXECUTION_ERROR: Error while executing command: npm publish. Reason: exit status 1"
],
"start-time": "Aug 24, 2022 9:01:06 AM",
"end-time": "Aug 24, 2022 9:01:11 AM",
"duration-in-seconds": 4,
"phase-type": "BUILD",
"phase-status": "FAILED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:01:11 AM",
"end-time": "Aug 24, 2022 9:01:11 AM",
"duration-in-seconds": 0,
"phase-type": "POST_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:01:11 AM",
"end-time": "Aug 24, 2022 9:01:11 AM",
"duration-in-seconds": 0,
"phase-type": "UPLOAD_ARTIFACTS",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [": "],
"start-time": "Aug 24, 2022 9:01:11 AM",
"end-time": "Aug 24, 2022 9:01:13 AM",
"duration-in-seconds": 2,
"phase-type": "FINALIZING",
"phase-status": "SUCCEEDED"
},
{
"start-time": "Aug 24, 2022 9:01:13 AM",
"phase-type": "COMPLETED"
}
],
"queued-timeout-in-minutes": 480
},
"current-phase": "COMPLETED",
"current-phase-context": "[: ]",
"version": "1"
}
}
I had the same task. I tried to find any solution. I tried to implement the following script: https://github.com/thii/aws-codebuild-extras. But there is a problem with moving environment variables to lambda.
So finally I solved it using the following steps:
I print author email in buildSpec.yml file:
pre_build:
commands:
- AUTHOR_EMAIL="$(git log -1 --pretty=%ae)"
- echo "CODEBUILD_GIT_AUTHOR_EMAIL=$AUTHOR_EMAIL"
I get all logs from CloudWatch in my lambda handler and find string by pattern ^CODEBUILD_GIT_AUTHOR_EMAIL=(.*)$
I send message to this email using AWS SES inside my lambda handler
Very bad solution, but it works. I can't cost more time for this task
I have documents like this..
"auction_list": [
{
"auction_id": 11368494,
"domain": "51love.cn",
"utf_name": "51love.cn",
"is_idn": false,
"auction_type": "backorder",
"currency": "USD",
"current_bid_price": "36.00",
"bids": 25,
"bidders": 4,
"time_left": "4 days, 5 hours",
"start_time": "2021/06/15 14:30 PST",
"start_time_stamp": 1623792604841,
"end_time": "2021/06/22 03:02 PST",
"end_time_stamp": 1624356147000,
"estibot_appraisal": "$0.00"
},
{
"auction_id": 11381539,
"domain": "meiguihualove.cn",
"utf_name": "meiguihua.cn",
"is_idn": false,
"auction_type": "backorder",
"currency": "USD",
"current_bid_price": "15.99",
"bids": 5,
"bidders": 4,
"time_left": "5 days, 5 hours",
"start_time": "2021/06/16 14:30 PST",
"start_time_stamp": 1623879010264,
"end_time": "2021/06/23 03:02 PST",
"end_time_stamp": 1624442573000,
"estibot_appraisal": "$0.00"
},
{
"auction_id": 11273186,
"domain": "surpass.cn",
"utf_name": "surpass.cn",
"is_idn": false,
"auction_type": "backorder",
"currency": "USD",
"current_bid_price": "14.99",
"bids": 4,
"bidders": 4,
"time_left": "1 day, 5 hours",
"start_time": "2021/06/09 14:30 PST",
"start_time_stamp": 1623274205156,
"end_time": "2021/06/19 03:02 PST",
"end_time_stamp": 1624096958000,
"estibot_appraisal": "$40.00"
}
I have total 30000 objects in that array.
I want to search for the domain if the domain word contain love (with regex). and want to slice the result first 1 to 50th item and them 50th to 100 if found?
I tried
ExpiredDomains.find({auction_list:{$elemMatch:{domain:'/love/'}}})
and
ExpiredDomains.find({auction_list:{$elemMatch:{domain:{$regex: 'love'}}})
but this return nothing.
how can I do that? I am using Node js.
Thanks in Advance
Below aggregation can filter all the records with a regex.
db.collection.aggregate([
{
"$project": {
"auction_list": {
"$filter": {
"input": "$auction_list",
"as": "list",
cond: {
"$regexMatch": {
"input": "$$list.domain",
"regex": /love/
}
}
}
}
}
},
{
"$unwind": "$auction_list"
},
{
"$skip": 0
},
{
"$limit": 50
}
])
Edit: For limiting and skipping.
Assing two different variable:
const a = 0;
const b = 50;
//And use it like
{
"$skip": a
},
{
"$limit": b
}
And dynamically change them. Skip will ignore first x record. If you'd give skip = 50 limit = 100 You'll get second 50 record.
I'm trying to create an EventBridge Event Pattern that matches a CodeBuild state change only when a specific string is present in "phase-context" of one of the objects within the "phases" array.
I've been unable to find an example of how to match a single objects property within an array of objects. Is it possible? I know I could look to match a CodeBuild phases change event instead but want to avoid that if possible.
I have marked in the string I want to match in the example CodeBuild state change event below:
{
"version": "0",
"id": "c030038d-8c4d-6141-9545-00ff7b7153EX",
"detail-type": "CodeBuild Build State Change",
"source": "aws.codebuild",
"account": "123456789012",
"time": "2017-09-01T16:14:28Z",
"region": "us-west-2",
"resources":[
"arn:aws:codebuild:us-west-2:123456789012:build/my-sample-project:8745a7a9-c340-456a-9166-edf953571bEX"
],
"detail":{
"build-status": "SUCCEEDED",
"project-name": "my-sample-project",
"build-id": "arn:aws:codebuild:us-west-2:123456789012:build/my-sample-project:8745a7a9-c340-456a-9166-edf953571bEX",
"additional-information": {
"artifact": {
"md5sum": "da9c44c8a9a3cd4b443126e823168fEX",
"sha256sum": "6ccc2ae1df9d155ba83c597051611c42d60e09c6329dcb14a312cecc0a8e39EX",
"location": "arn:aws:s3:::codebuild-123456789012-output-bucket/my-output-artifact.zip"
},
"environment": {
"image": "aws/codebuild/standard:4.0",
"privileged-mode": false,
"compute-type": "BUILD_GENERAL1_SMALL",
"type": "LINUX_CONTAINER",
"environment-variables": []
},
"timeout-in-minutes": 60,
"build-complete": true,
"initiator": "MyCodeBuildDemoUser",
"build-start-time": "Sep 1, 2017 4:12:29 PM",
"source": {
"location": "codebuild-123456789012-input-bucket/my-input-artifact.zip",
"type": "S3"
},
"logs": {
"group-name": "/aws/codebuild/my-sample-project",
"stream-name": "8745a7a9-c340-456a-9166-edf953571bEX",
"deep-link": "https://console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEvent:group=/aws/codebuild/my-sample-project;stream=8745a7a9-c340-456a-9166-edf953571bEX"
},
"phases": [
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:12:29 PM",
"end-time": "Sep 1, 2017 4:12:29 PM",
"duration-in-seconds": 0,
"phase-type": "SUBMITTED",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:12:29 PM",
"end-time": "Sep 1, 2017 4:13:05 PM",
"duration-in-seconds": 36,
"phase-type": "PROVISIONING",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:13:05 PM",
"end-time": "Sep 1, 2017 4:13:10 PM",
"duration-in-seconds": 4,
"phase-type": "DOWNLOAD_SOURCE",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:13:10 PM",
"end-time": "Sep 1, 2017 4:13:10 PM",
"duration-in-seconds": 0,
"phase-type": "INSTALL",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:13:10 PM",
"end-time": "Sep 1, 2017 4:13:10 PM",
"duration-in-seconds": 0,
"phase-type": "PRE_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [
"something here" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< THIS STRING
],
"start-time": "Sep 1, 2017 4:13:10 PM",
"end-time": "Sep 1, 2017 4:14:21 PM",
"duration-in-seconds": 70,
"phase-type": "BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:14:21 PM",
"end-time": "Sep 1, 2017 4:14:21 PM",
"duration-in-seconds": 0,
"phase-type": "POST_BUILD",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:14:21 PM",
"end-time": "Sep 1, 2017 4:14:21 PM",
"duration-in-seconds": 0,
"phase-type": "UPLOAD_ARTIFACTS",
"phase-status": "SUCCEEDED"
},
{
"phase-context": [],
"start-time": "Sep 1, 2017 4:14:21 PM",
"end-time": "Sep 1, 2017 4:14:26 PM",
"duration-in-seconds": 4,
"phase-type": "FINALIZING",
"phase-status": "SUCCEEDED"
},
{
"start-time": "Sep 1, 2017 4:14:26 PM",
"phase-type": "COMPLETED"
}
]
},
"current-phase": "COMPLETED",
"current-phase-context": "[]",
"version": "1"
}
}
EventBridge supports value matches within array (https://docs.aws.amazon.com/eventbridge/latest/userguide/arrays-in-eventbridge-event-patterns.html). I'm not certain but AFAIK it doesn't support patterns within an array. To be sure, I'd recommend trying out the filters specified in https://docs.aws.amazon.com/eventbridge/latest/userguide/content-filtering-with-event-patterns.html within a rule pattern.
If this fails, you would need to setup a lambda (or fargate / ec2) to transform the input before calling put-events again.
Is there a way to send multiple data in a single metric using aws cloudwatch cli.
Have you tried specifying a json object and putting multiple items within that list?
i.e.
aws cloudwatch put-metric-data --namespace "Usage Metrics" --metric-data file://metric.json
Where metric.json is something like:
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Value": 0.50,
"Unit": "Count"
},
{
"MetricName": Metric2,
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Value": 1,
"Unit": "Count"
},
{
"MetricName": "Metric 2",
"Timestamp": "Wednesday, November 2, 2013 8:29:20 AM",
"Value": 5,
"Unit": "Count"
}
]
if you need to send multiple values for one metric, something like:
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"Values": [0.50,2,3,5.1],
"Unit": "Count"
}
]
or
[
{
"MetricName": "Metric1",
"Timestamp": "Wednesday, November 2, 2013 8:28:20 AM",
"StatisticValues": {
"SampleCount": 8,
"Sum": 18,
"Minimum": 2.3,
"Maximum": 2.7
},
"Unit": "None"
}
]