Skip to content

Instantly share code, notes, and snippets.

View bmccann36's full-sized avatar

Brian McCann bmccann36

View GitHub Profile
public class Handler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
private static final Logger LOG = Logger.getLogger(Handler.class);
@Override
public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
LOG.info("received: " + input);
Response responseBody = new Response("Go Serverless v1.x! Your function executed successfully!", input);
return ApiGatewayResponse.builder()
.setStatusCode(200)
.setObjectBody(responseBody)
.setHeaders(Collections.singletonMap("X-Powered-By", "AWS Lambda & serverless"))
functions:
hello:
  handler: com.serverless.Handler
# from here down is new
  events:
  - http:
  path: myresourcepath
  method: ANY
@ComponentScan(
basePackages = "your.base.package",
excludeFilters = {@Filter(type = ASSIGNABLE_TYPE, value = {
ExcludedAppConfig1.class, ExcludedAppConfig2.class})
})
public class TestConfig { ...
}
functions:
hello: # defines a function named "hello"
  handler: com.serverless.Handler # tells the framework where to find the entry point
functions:
bookStoreApp: # the bookStoreApp function houses the whole app
handler: com.springbootslsdemo.SpringLambdaHandler
events:
- http:
path: /
method: ANY
  - http:
  path: /{proxy+} # all REST resource paths will lead to this function being invoked
# the spring boot framework will handle the routing to the correct classes
functions:
create: #defines a function named create
handler: com.notesservice.CreateNote # points to the location of the code to invoke
events: # defines what type of event will trigger the invocation
- http: # creates a REST endpoint for you
path: notes # calling POST - {apiGatewayUrl}/notes will lead to this function's invocation
method: post
get:
handler: com.notesservice.GetNote
events:
@bmccann36
bmccann36 / invoke-lambda-sample.js
Last active October 11, 2020 14:02
example of invoking a Lambda function from Javascript api
const params = {
FunctionName: "my-function", InvocationType: "Event", Payload: "<Binary String>", Qualifier: "1"
};
lambda.invoke(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
@bmccann36
bmccann36 / creds.java
Created July 4, 2020 11:52
zeebe credentials sourcing
if (accessKey == null) {
logger.info("Creating Lambda client without credentials the container will use task IAM role ");
Regions region = Regions.fromName(this.region);
AWSLambdaClientBuilder builder = AWSLambdaClientBuilder.standard()
.withRegion(region);
client = builder.build();
} else {
logger.info("Creating Lambda client with provided access and secret key");
Regions region = Regions.fromName(this.region);
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secret);
@bmccann36
bmccann36 / role.yml
Created July 3, 2020 14:48
zeebe lambda example
- PolicyName: zeebeWorkerInvokePolicy
PolicyDocument:
Version: '2012-10-17'
Statement: # we are granting the following permissions to the following resources
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
# resolves to 'arn:aws:lambda:*:<your-acct-id>:function:trip-booking-functions*'
Resource: