Sitemap

Sunday, December 29, 2019

Concepts: Serverless and AWS Lambda

Serverless computing (or serverless for short), is an execution model where the cloud provider (AWS, Azure, or Google Cloud) is responsible for executing a piece of code by dynamically allocating the resources. You will only get charged for the time that your function executes. The code is typically run inside stateless containers that can be triggered by a variety of events including HTTP requests, database events, queuing services, monitoring alerts, file uploads, scheduled events (Cron jobs), etc. The code that is sent to the cloud provider for execution is usually in the form of a function. Hence serverless is sometimes referred to as “Functions as a Service” or “FaaS”.

Principles of Serverless
1. Use a compute service to execute code  on demand
2. Write single-purpose stateless functions
3. Design push-based, event-driven pipelines
4. Create thicker, more powerful front ends
5. Embrace third-party services

Tenets of Serverless
  • You bring the code, provider brings the infrastructure
  • Scale seamlessly with demand
  • Pay as you go, but never pay for idle time

Serverless Patterns
  • Compute as Back End
  • Compute as Glue
  • Command pattern
  • Messaging pattern
  • Priority queue pattern
  • Fan-out pattern
  • Pipes and filters pattern

Serverless Components
  • Lambda: Functions as a Service (compute)
  • API Gateway: HTTP endpoints as a Service (connectivity)
  • DynamoDB: Managed NoSQL (storage)
  • S3: Managed object store (storage)
  • Cognito: User management & authentication (security)
  • Certificate Manager: free, automatic SSL certs (security)

Use Cases of Lambda
  • ETL jobs
  • APIs (with API Gateway)
  • Mobile backends
  • Infrastructure automation
  • Data validation
  • Security remediation

Under the hood, when you are using Lambda, you are using containers that are running on EC2 instances, which are not accessible by you in terms of administration and management. They download your code from Lambda and run it inside of an isolated container. So it looks to you like you have an isolated machine even though there may be many lambDa functions executing at the same time on that machine. These containers enforce resource isolations so you are only allowed to use the amount of RAM that you have configured and they enforce 100ms execution limit for the purpose of billing and also for timeouts. At the end of the timeout, the container will be killed regardless of the state of your process.

Your application is composed of
  • the code that you provide and any dependencies of your code such as external libraries.
  • the event that comes in from the external service
  • the output is what your function sends back whether it sends to an external service or returns it as the output of the function

Event sources
  • Schedules: similar to a cronjob
  • S3 events: which hands the information about a new/deleted/changed file into Lambda
  • DynamoDB streams:  when a change is made in DynamoDB
  • Kinesis streams
  • SNS topics: simple notification service, messages that come in from webhooks or any other sources
  • API Gateway: mapping between HTTP request that might be coming in and events being sent to your Lambda functions
  • AppSync
  • CloudTrail logs
  • EC2 Lifecycle events
  • SDK invocation: language SDKs for different languages like Perl, PHP, JS, Python; from any of these, you can invoke your Lambda function and just let it run async or wait around for the result

Thursday, September 13, 2018

Salesforce: Links at my click!

External IDs
http://www.salesforcefinessed.com/2017/10/why-should-you-care-about-external-ids.html

aura:method
https://quirkyapex.com/2018/03/18/lightning-component-methods/

Data Loader with Command Line
https://kloudrac.com/blog/data-loader-with-command-line/

Platform Events
http://www.mstsolutions.com/blog/content/platform-events
https://andyinthecloud.com/2017/11/12/platform-events-and-lightning-components/
https://trailhead.salesforce.com/projects/workshop-platform-events

Apex Code Coverage hack
https://pavelslepenkovdotinfo.wordpress.com/2013/07/27/apex-code-coverage-hack/

Elements of a Salesforce Workflow Rule
https://cloudcraze.com/the-elements-of-a-salesforce-workflow-rule-workflow-deep-dive-pt-i/
https://cloudcraze.com/real-world-examples-of-salesforce-workflow-rules-workflow-deep-dive-pt-ii/

Truthy and Falsy Values in JavaScript
http://adripofjavascript.com/blog/drips/truthy-and-falsy-values-in-javascript.html

CSS Selectors
https://learn.shayhowe.com/advanced-html-css/complex-selectors/

Javascript: Pagination
https://gist.github.com/kottenator/9d936eb3e4e3c3e02598

Events: Bubbling and capturing
https://javascript.info/bubbling-and-capturing

Triggers and order of execution
https://albasfdc.wordpress.com/2016/12/19/triggers-and-order-of-execution/

Salesforce Apex: Maps
http://www.iterativelogic.com/working-with-apex-code-maps/

Apex: Sorting Wrapper list based on multiple conditions
https://salesforce.stackexchange.com/questions/192818/sort-wrapper-list-in-apex-based-on-levels
http://blog.deadlypenguin.com/blog/2015/10/10/comparable-sorting-objects-in-salesforce/

lightning:container
https://developer.salesforce.com/blogs/2018/04/lightning-container-component-building-components-with-react-angular-and-other-libraries.html

Lightning Service Components
https://developer.salesforce.com/blogs/2018/08/implement-and-use-lightning-service-components.html

Communication: Lightning Components and Visualforce Pages
https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html



SOQL Builder: apex-commons
http://apex-commons.github.io/query/soql-builder/
https://github.com/apex-commons/SoqlBuilder

Salesforce Security Token and Password Policies
http://webkul.com/blog/salesforce-security-token/
http://www.infallibletechie.com/2012/12/password-policies-are-user-security.html

Which Automation Tool Do I Use?
https://help.salesforce.com/articleView?id=process_which_tool.htm

Modifying Components Outside the Framework Lifecycle
http://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

How to write SOQL to traverse across two objects and their junction object
http://kingkoo-salesforce.blogspot.in/2012/12/how-to-write-soql-to-traverse-across.html

Best practices for writing code that doesn’t exceed certain governor limits.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_limits_tips.htm
https://developer.salesforce.com/page/Apex_Code_Best_Practices
https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1

Pop, Push, Shift and Unshift Array Methods in JavaScript
https://alligator.io/js/push-pop-shift-unshift-array-methods/

JS events: target vs currentTarget
https://javascript.info/bubbling-and-capturing

Prototypes in JavaScript
https://hackernoon.com/prototypes-in-javascript-5bba2990e04b

How to Select All Fields with SOQL in Apex
https://douglascayers.com/2015/10/08/salesforce-how-to-select-all-fields-with-soql-in-apex/

Salesforce: Setting Up Your Java Developer Environment
Link: https://resources.docs.salesforce.com/210/latest/en-us/sfdc/pdf/salesforce_developer_environment_tipsheet.pdf




Downloadable Salesforce User Guides
Set Up and Maintain Your Salesforce Organization
https://resources.docs.salesforce.com/212/latest/en-us/sfdc/pdf/setup.pdf

Sales Cloud Basics
https://resources.docs.salesforce.com/214/latest/en-us/sfdc/pdf/sales_core.pdf

Enhance Salesforce with Point and Click Tools
https://resources.docs.salesforce.com/214/latest/en-us/sfdc/pdf/extend_click.pdf

Enhance Salesforce with Code
https://resources.docs.salesforce.com/214/latest/en-us/sfdc/pdf/extend_code.pdf

List of important StackExchange links

How can I efficiently generate a Set<Id> from a List<SObject>
https://salesforce.stackexchange.com/questions/8910/how-can-i-efficiently-generate-a-setid-from-a-listsobject-structure

Why are foreach loops slower in Apex than standard for loop?
https://salesforce.stackexchange.com/questions/227272/why-are-foreach-loops-slower-in-apex-than-standard-for-loop


Monday, April 2, 2018

Machine learning crash course from Google

https://ai.google/education#?modal_active=none
https://developers.google.com/machine-learning/crash-course/

Wednesday, May 24, 2017

AEM: SegmentNotFoundException Segment not found

A SegmentNotFoundException in the error log means a segment is not present any more although we are still trying to access it.

To resolve this, please follow the below steps:

Download oak-run jar file from here http://repo1.maven.org/maven2/org/apache/jackrabbit/oak-run/
* AEM6.0 - If using Oak 1.0.12 or later then use Oak 1.1.8 - oak-run-1.1.8.jar. If the Oak version is 1.0.11 or earlier then use oak-run 1.1.6.
Note: We are using a 1.1.x branch version of oak-run because 1.0.x branch doesn't have the "check" command implemented.

1) Stop AEM

2) Run this command:
java -jar oak-run-*.jar check -d1 --bin=-1 -p crx-quickstart/repository/segmentstore/
It which will search backwards through the revisions until it finds a consistent one, Example:
14:00:30.783 [main] INFO o.a.j.o.p.s.f.t.ConsistencyChecker - Found latest good revision afdb922d-ba53-4a1b-aa1b-1cb044b535cf:234880

3)Revert the repository to this revision by editing ./crx-quickstart/repository/segmentstore/journal.log. Delete all lines after the line containing the latest good revision.
If you would like to find out what date and time you are reverting the repository to then run this command in the segmentstore folder (replace afdb922d-ba53-4a1b-aa1b-1cb044b535cf with the latest good revision in your journal.log):
find . -type f -name "data*.tar" -exec sh -c "tar -tvf {} |grep afdb922d-ba53-4a1b-aa1b-1cb044b535cf" \; -print
The output would show you an approximate date and time of that revision.

4)Remove all ./crx-quickstart/repository/segmentstore/*.bak files.

5)If using AEM6.0 then download the oak-run version matching what is installed in AEM for the remaining steps. Download it from here http://repo1.maven.org/maven2/org/apache/jackrabbit/oak-run/

6)Run checkpoint clean-up to remove orphaned checkpoints:
java -jar oak-run-*.jar checkpoints ./crx-quickstart/repository/segmentstore rm-unreferenced

7)Finally compact the repository:
java -jar oak-run-*.jar compact ./crx-quickstart/repository/segmentstore/


After the Above steps are completed, your system should now boot up properly.

Tuesday, January 24, 2017

Utility for taking backup of AEM contents

This utility is in the form of a unix shell script. The script will take the backup of AEM contents present in production author instance, create a zip file of it, download it and keep it in a particular location as defined in the script. Once the process is completed, an email will be sent to users to let them know the status of the job, whether the process was a success or resulted in an error. To automate this entire process, a cronjob can be set up which needs to be scheduled.

The technical document and the script are attached in a zip file. Check the downloads section for the zip file.

Friday, August 5, 2016

UCM: GET_SEARCH_RESULTS iterating resultset

package com.company;

import oracle.stellent.ridc.IdcClient;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.model.DataObject;
import oracle.stellent.ridc.model.DataResultSet;
import oracle.stellent.ridc.protocol.ServiceResponse;

import java.util.List;

/**
 * Created by Sonal_Chaudhary on 8/4/2016.
 */
public class ExtractEmailIDs {
    public static void main(String[] args) {
        int startIndex = 1;
        int pageNumber = 1;
        int totalRows = 20;
        IdcClientManager manager = new IdcClientManager();
        try {
            IdcClient idcClient = manager.createClient("idc://143.127.54.171:4444");
            IdcContext userContext = new IdcContext("sysadmin");

            boolean stillLoop = true;
            while (stillLoop) {
                DataBinder dataBinder = idcClient.createBinder();
                dataBinder.putLocal("IdcService", "GET_SEARCH_RESULTS");
                dataBinder.putLocal("QueryText", "dSecurityGroup <contains> `Partner`  <AND>  xLanguage <contains> `4`  <AND>  xCountries <contains> `1`");
                dataBinder.putLocal("SearchQueryFormat", "Universal");
                dataBinder.putLocal("StartRow", Integer.toString(startIndex));
                dataBinder.putLocal("ResultCount",  Integer.toString(totalRows));
                dataBinder.putLocal("PageNumber",  Integer.toString(pageNumber));
                dataBinder.putLocal("TotalRows",  Integer.toString(totalRows));

                ServiceResponse response = idcClient.sendRequest(userContext, dataBinder);
                DataBinder responseData = response.getResponseAsBinder();
                DataResultSet resultSet = responseData.getResultSet("SearchResults");

                if (resultSet != null && resultSet.getRows() != null) {
                    List<DataObject> dataObjects = resultSet.getRows();
                    if (dataObjects.size() == totalRows) {
                        startIndex += totalRows;
                        pageNumber++;
                    } else {
                        stillLoop = false;
                    }
                    for (DataObject dataObject : dataObjects) {
                        System.out.println(dataObject.get("dID") + "," + dataObject.get("dDocName") + "," + dataObject.get("dExtension"));
                    }
                }
            }
        } catch (IdcClientException ice) {
            ice.printStackTrace();
        }
    }
}