Skip to content

Instantly share code, notes, and snippets.

View swapnonil's full-sized avatar

Swapnonil Mukherjee swapnonil

  • London
View GitHub Profile
@swapnonil
swapnonil / README.md
Created January 4, 2019 18:32 — forked from magnetikonline/README.md
CloudFormation example for an API Gateway endpoint calling a Lambda function using proxy integration.

CloudFormation example for API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway endpoint:
    • A single root method, accepting POST requests only with Lambda proxy integration to a function.
  • In-line Lambda function echoing back requesting users IP address to API Gateway requests:
    • IAM role for Lambda allowing CloudWatch logs access.
    • Permissions for Lambda that allow API Gateway endpoint to successfully invoke function.
  • CloudWatch logs group for Lambda, with 90 day log retention.

After standing up the template, you should be able to curl a POST request to the URL listed as the apiGatewayInvokeURL output value.

ObjectMetadata md = new ObjectMetadata();
md.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
md.setHeader(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, kmsKeyId);
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": "arn:aws:s3:::swap-third-party/*.pdf"
}
public void copy(String sourceLocation, String destinationLocation, String sourceFileName, String destinationFileName, SSEAlgorithm destinationSSEAlgorithm, String destinationKMSKeyId) throws InterruptedException {
ObjectMetadata md = new ObjectMetadata();
if (destinationSSEAlgorithm.getAlgorithm().equals(SSEAlgorithm.KMS.getAlgorithm())) {
md.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm());
md.setHeader(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, destinationKMSKeyId);
}
transferManager = new TransferManager(new ClasspathPropertiesFileCredentialsProvider());
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourceLocation, sourceFileName, destinationLocation, destinationFileName).withNewObjectMetadata(md);
public class ShoppingCartITest {
ShoppingCart shoppingCart;
private Product product;
private User user;
@Before
public void setUp() throws Exception {
shoppingCart = new ShoppingCart();
}
public class ShoppingCartUTest {
ShoppingCart shoppingCart;
private MockProduct mockProduct;
private MockUser mockUser;
@Before
public void setUp() throws Exception {
shoppingCart = new ShoppingCart();
}
@swapnonil
swapnonil / ShoppingCart.java
Last active August 29, 2015 14:21
How I Test Business Logic
public class ShoppingCart {
private AuditGateway auditGateway;
private User user;
public void applyDiscount(int productId) {
// find the product which has been already been added to the cart
Product product = getProduct(productId);
if (product == null || user == null) {
throw new IllegalArgumentException("Either product or user is invalid");
package functions
object BasicFunctions {
def main(args: Array[String]) = {
val person = personInfo(100)
println(person._1, person._2, person._3, person._4)
// Another way of creating a simple Tuple. This creates a key, value pair
val data = "red" -> 1900
println(data._1, data._2)
@swapnonil
swapnonil / build.xml
Last active August 29, 2015 13:56
Ant build script with Sonar, Jacoco Integration
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="SomeLegacyCode" xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property environment="env" />
<property name="ECLIPSE_HOME" value="../../" />
<property name="debuglevel" value="source,lines,vars" />
@swapnonil
swapnonil / apt.conf
Created February 26, 2013 10:53
Ubuntu Proxy configuration for Apt.
Go to /etc/apt. Create the file apt.conf if you don't have it there. Write the following lines there.
Acquire::http::proxy "http://username:password@proxyserver:port/";
Acquire::https::proxy "https://username:password@proxyserver:port/";
Acquire::socks::proxy "socks://username:password@proxyserver:port/";