Skip to content

Instantly share code, notes, and snippets.

Avatar

Frédéric Barthelet fredericbarthelet

View GitHub Profile
@fredericbarthelet
fredericbarthelet / create.ts
Last active Jun 30, 2021
Lamba create.ts with intrinsic service
View create.ts
import { DynamoDB } from 'aws-sdk';
import { ref } from './intrinsic';
import cloudformationResources, { MyTable } from './resources';
export default {
handler:'create.main',
environment: {
TABLE_NAME: ref(cloudformationResources, MyTable)
},
@fredericbarthelet
fredericbarthelet / intrinsic.ts
Created Oct 11, 2020
AWS intrinsic function resolution
View intrinsic.ts
import {
CloudFormationResource,
CloudFormationResources,
} from 'serverless/aws';
import { findKey } from 'lodash';
interface CloudFormationReference {
Ref: string;
}
@fredericbarthelet
fredericbarthelet / create.ts
Last active Jun 30, 2021
lambda with dynamo
View create.ts
import { DynamoDB } from 'aws-sdk';
export default {
handler:'create.main',
environment: {
TABLE_NAME: {
Ref: 'MyTable'
}
},
events: [
@fredericbarthelet
fredericbarthelet / functions.ts
Last active Jun 30, 2021
Serverless.ts complex project imports
View functions.ts
export { default as hello } from './hello';
export { default as goodbye } from './goodbye';
@fredericbarthelet
fredericbarthelet / functions.ts
Created Oct 11, 2020
Serverless.ts splitting
View functions.ts
export default {
hello: {
handler: 'index.hello'
},
goodbye: {
handler: 'index.goodbye'
}
};
@fredericbarthelet
fredericbarthelet / functions.yml
Created Oct 11, 2020
Serverless.yml splitting
View functions.yml
hello:
handler: index.hello
goodbye:
handler: index.goodbye
@fredericbarthelet
fredericbarthelet / serverless.yml
Last active Oct 11, 2020
Serverless all-in-one definition
View serverless.yml
service: myServerlessService
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: index.hello
goodbye:
@fredericbarthelet
fredericbarthelet / s3-bucket.yml
Created Apr 26, 2020
CloudFormation template
View s3-bucket.yml
AWSTemplateFormatVersion: 2010-09-09
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
DeletionPolicy: Retain
View CountingEventListener.php
namespace App\EventListener;
use App\Entity\Counting;
use App\Entity\User;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Symfony\Component\Security\Core\Security;
class CountingEventListener
{
/**
View index.js
const request = require(‘request’);
const url = require(‘url’);
function mySwitch(log, config) {
 this.log = log;
 this.getUrl = url.parse(config[‘getUrl’]);
 this.postUrl = url.parse(config[‘postUrl’]);
}
mySwitch.prototype = {
getSwitchOnCharacteristic: function (next) {
 const me = this;