UNPKG

serverless-aws-lambda

Version:

AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.

2 lines (1 loc) 2.78 kB
var R=(a,r)=>(r&&(r.override&&Object.entries(r.override).forEach(f=>{let[t,n]=f;t in a&&(a[t]=n)}),r.default&&Object.entries(r.default).forEach(f=>{let[t,n]=f;a[t]==null&&(a[t]=n)})),a),v=a=>{let{QueueName:r,ContentBasedDeduplication:f,DeduplicationScope:t,DelaySeconds:n,FifoQueue:e,FifoThroughputLimit:s,KmsDataKeyReusePeriodSeconds:i,KmsMasterKeyId:d,MaximumMessageSize:l,MessageRetentionPeriod:p,ReceiveMessageWaitTimeSeconds:m,VisibilityTimeout:g,Tags:u,RedrivePolicy:c}=a,y={QueueName:r};u&&Object.keys(u).length&&(y.tags=u);let o={};return typeof f<"u"&&(o.ContentBasedDeduplication=f),typeof t<"u"&&(o.DeduplicationScope=t),typeof n<"u"&&(o.DelaySeconds=n),typeof e<"u"&&(o.FifoQueue=e),typeof s<"u"&&(o.FifoThroughputLimit=s),typeof i<"u"&&(o.KmsDataKeyReusePeriodSeconds=i),typeof d<"u"&&(o.KmsMasterKeyId=d),typeof l<"u"&&(o.MaximumMessageSize=l),typeof p<"u"&&(o.MessageRetentionPeriod=p),typeof m<"u"&&(o.ReceiveMessageWaitTimeSeconds=m),typeof g<"u"&&(o.VisibilityTimeout=g),typeof c<"u"&&(o.RedrivePolicy=JSON.stringify({deadLetterTargetArn:c.deadLetterTargetArn,maxReceiveCount:c.maxReceiveCount})),r.endsWith(".fifo")&&(o.FifoQueue="true"),Object.keys(o).length&&(y.Attributes=o),y},h=(a,r,f)=>{let t=Object.values(a),n=e=>{if(t.findIndex(i=>i.QueueName==e)==-1){let i={QueueName:e};return t.push(i),!0}};return r.forEach(e=>{e.sns.forEach(s=>{typeof s.redrivePolicy=="string"&&n(s.redrivePolicy)}),e.ddb.forEach(s=>{s.onFailure?.kind=="sqs"&&n(s.onFailure.name)}),e.kinesis.forEach(s=>{s.onFailure?.kind=="sqs"&&n(s.onFailure.name)}),e.onError?.kind=="sqs"&&n(e.onError.name),e.onFailure?.kind=="sqs"&&n(e.onFailure.name),e.onSuccess?.kind=="sqs"&&n(e.onSuccess.name),e.sqs.forEach(s=>{n(s.name)})}),t.forEach(e=>{e.RedrivePolicy&&n(e.RedrivePolicy.name)}),t.map(e=>v(R(e,f)))};import{createRequestHandler as S}from"local-aws-sqs";var b=a=>{let r=(i,d)=>{},f,t,n=[],e=async()=>{s.pluginData.isReady=!0;for(let i of n)try{await i()}catch{}},s={name:"sqs-plugin",pluginData:{isReady:!1,onReady:i=>{typeof i=="function"?n.push(i):console.warn("onReady callback must be a function")}},onInit:function(){if(!this.isDeploying&&!this.isPackaging){let i=this.serverless.service.provider.region;i&&(f=i),this.serverless.providers?.aws?.accountId&&(t=this.serverless.providers.aws.accountId)}},offline:{async onReady(i,d){this.getServices().sqs||await this.setServices({sqs:{region:"us-east-1",endpoint:`http://localhost:${i}/@sqs`,credentials:{accessKeyId:"fake",secretAccessKey:"fake"}}}),r=S({port:i,region:f,accountId:t,validateDlqDestination:!1,emulateQueueCreationLifecycle:!1,baseUrl:"/@sqs/",queues:h(this.resources.sqs,this.lambdas,a)}),e()},request:[{method:"POST",filter:"/@sqs",callback:function(i,d){r(i,d)}}]}};return s},I=b;export{I as default,b as sqsPlugin};