https://pulumi.com logo
#golang
Title
# golang
n

nice-engineer-43278

01/10/2022, 3:43 PM
Copy code
package main

import (
	"encoding/json"
	"fmt"
	"os"

	"<http://github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sqs|github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sqs>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

var (
	stage string

	queueNamePlayerFreezePrice string
)

func init() {
	queueNamePlayerFreezePrice = "PlayerFreezePrice"

	stage = os.Getenv("STAGE")

	if stage == "" {
		stage = "dev"
	}
}

func main() {
	name := queueNamePlayerFreezePrice

	pulumi.Run(func(ctx *pulumi.Context) error {
		// -----------------------------------------------------//
		// ---------------- DEAD LEATER QUEUE ------------------//
		// -----------------------------------------------------//

		deadQueuePfpName := fmt.Sprintf("%s-Dead-%s", name, stage)

		deadQueuePfp, err := sqs.NewQueue(ctx, deadQueuePfpName, &sqs.QueueArgs{
			DelaySeconds:           <http://pulumi.Int|pulumi.Int>(0),
			ReceiveWaitTimeSeconds: <http://pulumi.Int|pulumi.Int>(5),
			Tags: pulumi.StringMap{
				"stage": pulumi.String(stage),
			},
		})
		if err != nil {
			return err
		}

		ctx.Export(fmt.Sprintf("DeadQueue%s-id", name), deadQueuePfp.ID())
		ctx.Export(fmt.Sprintf("DeadQueue%s-arn", name), deadQueuePfp.Arn)

		// -----------------------------------------------------//
		// ----------------- MAIN EVENT QUEUE ------------------//
		// -----------------------------------------------------//

		redrivePolicyPfp, err := json.Marshal(map[string]interface{}{
			"deadLetterTargetArn": deadQueuePfp.Arn,
			"maxReceiveCount":     4,
		})
		if err != nil {
			return err
		}

		queueNamePfp := fmt.Sprintf("%s-%s", name, stage)

		queuePfp, err := sqs.NewQueue(ctx, queueNamePfp, &sqs.QueueArgs{
			DelaySeconds:           <http://pulumi.Int|pulumi.Int>(0),
			ReceiveWaitTimeSeconds: <http://pulumi.Int|pulumi.Int>(5),
			RedrivePolicy:          pulumi.String(string(redrivePolicyPfp)),
			Tags: pulumi.StringMap{
				"stage": pulumi.String(stage),
			},
		}, pulumi.DependsOn([]pulumi.Resource{
			deadQueuePfp,
		}))
		if err != nil {
			return err
		}

		ctx.Export(fmt.Sprintf("Queue%s-arn", name), queuePfp.ID())
		ctx.Export(fmt.Sprintf("Queue%s-arn", name), queuePfp.Arn)

		return nil
	})
}
3 Views