Skip to content

Commit

Permalink
Add initial /trigger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matushorvath committed May 22, 2023
1 parent a6da7c3 commit 5fccf9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ const processEvent = async (event) => {
return postStart(event);
}
throw new ResultError(405, 'Method Not Allowed');
} else if (event.resource === '/trigger') {
if (event.httpMethod === 'OPTIONS') {
return options(event);
} else if (event.httpMethod === 'POST') {
return postTrigger(event);
}
throw new ResultError(405, 'Method Not Allowed');
}
throw new ResultError(403, 'Forbidden');
};
Expand Down Expand Up @@ -120,6 +127,14 @@ const postStart = async (event) => {
return { status: created ? 201 : 200 };
};

const postTrigger = async (_event) => {
console.log('postTrigger: start');

console.log('postTrigger: done');

return { status: 501 };
};

// TODO This should be done in AWS API GateWay configuration, but I can't get that to work
const options = async (_event) => {
console.log('options');
Expand Down Expand Up @@ -168,7 +183,7 @@ const explainUsage = (event, error) => {
...`body: ${JSON.stringify(example, undefined, 4)}`.split('\n')
];
} else {
error.body.usage = ['start'].map(resource => `POST https://${hostname}/${resource}`);
error.body.usage = ['start', 'trigger'].map(resource => `POST https://${hostname}/${resource}`);
}
};

Expand Down
17 changes: 17 additions & 0 deletions template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ Resources:
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
/trigger:
options:
x-amazon-apigateway-integration:
uri: !Sub
"arn:aws:apigateway:${AWS::Region}:lambda:path\
/2015-03-31/functions/${AocBotApiFunction.Arn}/invocations"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
post:
x-amazon-apigateway-integration:
uri: !Sub
"arn:aws:apigateway:${AWS::Region}:lambda:path\
/2015-03-31/functions/${AocBotApiFunction.Arn}/invocations"
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
x-amazon-apigateway-binary-media-types:
- "application/json"

Expand Down

0 comments on commit 5fccf9e

Please sign in to comment.