Skip to content

Instantly share code, notes, and snippets.

@hongsw
Created May 2, 2022 06:24
Show Gist options
  • Save hongsw/d107abb7ef3cfcc8c1d3bd7e7bf696ff to your computer and use it in GitHub Desktop.
Save hongsw/d107abb7ef3cfcc8c1d3bd7e7bf696ff to your computer and use it in GitHub Desktop.
day-2-step-5-stock-emtpy-to-factory-lambda
const axios = require('axios');
const consumer = async (event) => {
for (const record of event.Records) {
console.log("record")
console.log(record)
const response = await axios.post(
'http://factory.p3.api.codestates-devops.be:8080/api/manufactures',
// '{\n "MessageGroupId": "stock-arrival-group",\n "MessageAttributeProductId": "CP-502101",\n "MessageAttributeProductCnt": 10,\n "MessageAttributeFactoryId": "FF-500293",\n "MessageAttributeRequester": "\uD64D\uAE38\uB3D9",\n "CallbackUrl": "http://factory.p3.api.codestates-devops.be:8080/api/manufactures"\n}',
{
'MessageGroupId': 'stock-arrival-group',
'MessageAttributeProductId': record.MessageAttributeProductId, // day1-step4 참조
'MessageAttributeProductCnt': 10,
'MessageAttributeFactoryId': record.MessageAttributeFactoryId,
'MessageAttributeRequester': '홍승우lambda',
'CallbackUrl': ''
},
{
headers: {
'Content-Type': 'application/json'
}
}
);
}
};
module.exports = {
consumer,
};
{
"name": "aws-stock-empty-consumer",
"version": "1.0.0",
"description": "Serverless Framework Node SQS Producer-Consumer on AWS",
"author": "",
"license": "MIT",
"devDependencies": {
"serverless-lift": "^1.15.0"
},
"dependencies": {
"axios": "^0.27.2"
}
}
service: aws-stock-empty-consumer
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs14.x
region: ap-northeast-2
functions:
consumer:
handler: handler.consumer
events:
- sqs:
arn:
Fn::GetAtt:
- MyQueue
- Arn
resources:
Resources:
MyQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: "sales-api-stock-empty-sqs"
plugins:
- serverless-lift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment