Skip to content

Commit

Permalink
fixing lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
grabnerandi committed Apr 27, 2018
1 parent 9f89561 commit f66b32f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can also [download the slides I used](https://github.com/Dynatrace/AWSDevOps
**Lets get this party started:** Before we launch the CloudFormation stack which will create all required resources (EC2 Instances, Lambdas, CodeDeploy, CodePipeline, API Gateway) lets make sure we have all pre-requisites covered!


## Pre-Requisits
## Pre-Requisites
1. You need an AWS account. If you don't have one [get one here](https://aws.amazon.com/)
1. You need a Dynatrace Account. Get your [Free SaaS Trial here!](http://bit.ly/dtsaastrial)
1. Optional: In case you want to use Ansible as automation platform, you need a license for Ansible Tower. [Get your license here.](https://www.ansible.com/workshop-license)
Expand All @@ -40,7 +40,7 @@ As we are going to use AWS CodeDeploy, AWS CodePipeline, AWS Lambda, DynamoDB, A

We need a couple of things to launch the CloudFormation Template
1. Your *Dynatrace Tenant ID*
2. Your *Dynatrace Tenant URL*: For SaaS that would be something like http://`<yourtenant>`.live.dynatrace.com. For Managed it would be http://`<yourserver>`/e/`<your-env-id>`
2. Your *Dynatrace Tenant URL*: For SaaS that would be something like `http://<yourtenant>.live.dynatrace.com`. For Managed it would be http://`<yourserver>/e/<your-env-id>`
3. Your *Dynatrace OneAgent for Linux Download URL*: Go to Deploy Dynatrace -> Start Installation -> Linux and copy the URL within the quotes as shown below:
![](./images/preparation_dynatraceoneagenturl.png)
4. A *Dynatrace API Token*: Go to Settings -> Integration -> Dynatrace API and create a new Token
Expand Down Expand Up @@ -520,4 +520,5 @@ Here are several snippets of this monspec file that should explain how it works:
## 6. Summary - Next Steps
I hope you enjoyed that tutorial and you saw the value of adding Dynatrace into your DevOps Pipeline. We discussed a couple of concepts on how to leverage the Automation API, Automated Tagging and Baselining to implement concepts such as Shift-Left and Self-Healing.
There is more that can be done. If you want to learn more check out my YouTube Channel on [Dynatrace FullStack Performance Clinics](http://bit.ly/oneagenttutorials)

If you have any further questions don't hesitate to ask!
Binary file modified copytos3/lambdas.zip
Binary file not shown.
46 changes: 28 additions & 18 deletions lambdas/handleDynatraceProblemNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ exports.handler = (event, context, callback) => {
}

var fullUrl = dtApiUtils.getDtTenantUrl() + "/api/v1/problem/details/" + notificationObject.PID + "/comments";
console.log("Comment URL: "+ fullUrl);
console.log("Comment Body: " + JSON.stringify(commentBody));
// console.log("Comment URL: "+ fullUrl);
// console.log("Comment Body: " + JSON.stringify(commentBody));
dtApiUtils.dtApiPost(fullUrl, dtApiUtils.getDtApiToken(), commentBody, function(statusCode, data) {
console.log("Push Comment to Dynatrace: " + fullUrl + " " + statusCode + "-" + data);
});
Expand Down Expand Up @@ -142,26 +142,36 @@ var deployPreviousRevisions = function(mostRecentEventsWithDeployData, index, ca
console.log("CodeDeploy Info: " + JSON.stringify(deployEventWithDeployData.CodeDeploy));
console.log("Lets deploy: " + JSON.stringify(params));

deployEventWithDeployData.CodeDeployResponse = "Created new Deployment: ";
callback(null, mostRecentEventsWithDeployData);

codedeploy.createDeployment(params, function(err, data) {
if(err) {
deployEventWithDeployData.CodeDeployResponse = err;
console.log("createDeployment failed: " + err);
} else {
deployEventWithDeployData.CodeDeployResponse = "Created new Deployment: " + data.deploymentId;
console.log("createDeployment succeeded: " + data.deploymentId);
}

// call ourself recursively if we have more work - otherwise call callback
index++;
// lets validate we have a validate revision!
if(params.revision == null) {
deployEventWithDeployData.CodeDeployResponse = "COULDNT find previous CodeDeploy Deployment! No rollback possible";
console.log("createDeployment failed: COULDNT find previous CodeDeploy Deployment!");
if(index < mostRecentEventsWithDeployData.length) {
deployPreviousRevisions(mostRecentEventsWithDeployData, index, callback);
} else {
callback(null, mostRecentEventsWithDeployData);
}
});
}
else {
// now lets deploy it!
codedeploy.createDeployment(params, function(err, data) {
if(err) {
deployEventWithDeployData.CodeDeployResponse = err;
console.log("createDeployment failed: " + err);
} else {
deployEventWithDeployData.CodeDeployResponse = "Created new Deployment: " + data.deploymentId;
console.log("createDeployment succeeded: " + data.deploymentId);
}

// call ourself recursively if we have more work - otherwise call callback
index++;
if(index < mostRecentEventsWithDeployData.length) {
deployPreviousRevisions(mostRecentEventsWithDeployData, index, callback);
} else {
callback(null, mostRecentEventsWithDeployData);
}
});
}
} else {
// call ourself recursively if we have more work - otherwise call callback
index++;
Expand All @@ -186,7 +196,7 @@ var findCodeDeployDeploymentInformation = function(mostRecentEvents, index, call
// lets see if there is a rollback deployment

// "previousRevision":{"revisionType":"S3","s3Location":{"bucket":"codepipeline-artifacts-agrabner-dynatracedevops","key":"SampleDevOpsPipeline/SampleDevO/075Icjq.zip","bundleType":"zip","version":"0tUa9GFNfLmnTA0l8oEejg4ODg.9sDzH","eTag":"9ae34d4b55ab28340ade5875173cb20f"}}
console.log("Previous Revision: " + data.previousRevision);
// console.log("Previous Revision: " + JSON.stringify(data.deploymentInfo));

event.CodeDeploy = data;

Expand Down
2 changes: 1 addition & 1 deletion lambdas/pushDynatraceDeploymentEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var postEventToDynatraceApi = function(postedData, codePipelineJobId, context) {
}

// lets log our call to Dynatrace
doPostWithRetry(dtEventUrl, postedData, event, codePipelineJobId, context, 5, 1000);
doPostWithRetry(dtEventUrl, postedData, event, codePipelineJobId, context, 5, 5000);
}

/**
Expand Down

0 comments on commit f66b32f

Please sign in to comment.