Skip to content

Instantly share code, notes, and snippets.

View gogarufi's full-sized avatar

Egor Iakovlev gogarufi

View GitHub Profile
@gogarufi
gogarufi / send-email-policy-document.json
Created February 19, 2017 19:09
Policy document which allows sending email to AWS SES
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:SendEmail"
],
"Resource": "*"
}
@gogarufi
gogarufi / lambda-ses-credentials.java
Created February 18, 2017 23:44
Setting up an AWS SES client credentials provider for a Lambda service
builder.setCredentials(new AWSCredentialsProvider() {
public AWSCredentials getCredentials() {
return new AWSCredentials() {
public String getAWSAccessKeyId() {
return "";
}
public String getAWSSecretKey() {
return "";
}
};
@gogarufi
gogarufi / pom-plugins.xml
Created February 14, 2017 01:32
Maven plugins section with "Shade" plugin which puts all project dependencies in a JAR while building it.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
@gogarufi
gogarufi / pom-dependencies.xml
Created February 14, 2017 01:28
Maven dependencies to include AWS SES and core AWS Lambda SDKs in a Java project
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ses</artifactId>
<version>1.11.86</version>
@gogarufi
gogarufi / pom.xml
Last active February 14, 2017 01:27
Maven POM template for AWS Lambda service
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>doc-examples</groupId>
<artifactId>lambda-java-example</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>lambda-java-example</name>
@gogarufi
gogarufi / EmailServiceException.java
Created February 13, 2017 22:21
Email service exception parent class
package com.gogarufi.lambda.ses;
class EmailServiceException extends Throwable {
EmailServiceException(Throwable e) {
super(e);
}
}
@gogarufi
gogarufi / EmailService.java
Created February 13, 2017 22:17
Email service class which uses AWS SDK to send email messages over HTTP through AWS SES
package com.gogarufi.lambda.ses;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.services.simpleemail.*;
import com.amazonaws.services.simpleemail.model.*;
import com.amazonaws.regions.*;
class EmailService {
static int send(String from, String to, String text, String subject) throws EmailServiceException {
try {
@gogarufi
gogarufi / EmailSender.java
Created February 13, 2017 22:13
AWS Lambda class with a public handler method
package com.gogarufi.lambda.ses;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import java.util.Map;
public class EmailSender {
public void send(Context context) {
LambdaLogger logger = context.getLogger();