From c02b3d3d8bdb18a591255bd1b0f3c160bb295dce Mon Sep 17 00:00:00 2001 From: Florian Stadler Date: Fri, 23 Aug 2024 19:46:29 +0200 Subject: [PATCH] Add example for deploying an application from the serverless app repository (#4396) This deploys theAthenaCloudwatchConnector from the Serverless Application Repository and sets it up as a data source in Athena. This allows users to query CloudWatch Logs using Athena. --- examples/examples_nodejs_test.go | 9 +++++ .../Pulumi.yaml | 3 ++ .../README.md | 4 ++ .../index.ts | 39 +++++++++++++++++++ .../package.json | 12 ++++++ .../tsconfig.json | 18 +++++++++ 6 files changed, 85 insertions(+) create mode 100644 examples/serverless-app-repository-application/Pulumi.yaml create mode 100644 examples/serverless-app-repository-application/README.md create mode 100644 examples/serverless-app-repository-application/index.ts create mode 100644 examples/serverless-app-repository-application/package.json create mode 100644 examples/serverless-app-repository-application/tsconfig.json diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index a70e7932a77..96cc8d018f4 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -724,3 +724,12 @@ func TestRegress4011(t *testing.T) { } integration.ProgramTest(t, &test) } + +func TestServerlessAppRepositoryApplication(t *testing.T) { + test := getJSBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: filepath.Join(getCwd(t), "serverless-app-repository-application"), + }) + + integration.ProgramTest(t, &test) +} diff --git a/examples/serverless-app-repository-application/Pulumi.yaml b/examples/serverless-app-repository-application/Pulumi.yaml new file mode 100644 index 00000000000..a28409b82ed --- /dev/null +++ b/examples/serverless-app-repository-application/Pulumi.yaml @@ -0,0 +1,3 @@ +name: serverless-app-repository-application +runtime: nodejs +description: Basic example of deploying an application from the serverless app repository. diff --git a/examples/serverless-app-repository-application/README.md b/examples/serverless-app-repository-application/README.md new file mode 100644 index 00000000000..6ac82dc8b47 --- /dev/null +++ b/examples/serverless-app-repository-application/README.md @@ -0,0 +1,4 @@ +# examples/serverless-app-repository-application + +Basic example of deploying an application from the serverless app repository. +This deploys the [`AthenaCloudwatchConnector`](https://serverlessrepo.aws.amazon.com/applications/ap-south-1/313922868085/AthenaCloudwatchConnector) from the Serverless Application Repository and sets it up as a data source in Athena. This allows you to query CloudWatch Logs using Athena. diff --git a/examples/serverless-app-repository-application/index.ts b/examples/serverless-app-repository-application/index.ts new file mode 100644 index 00000000000..c93a63ff5db --- /dev/null +++ b/examples/serverless-app-repository-application/index.ts @@ -0,0 +1,39 @@ +import * as pulumi from "@pulumi/pulumi"; +import * as aws from "@pulumi/aws"; + +const config = new pulumi.Config("aws"); +const providerOpts = { provider: new aws.Provider("prov", { region: config.require("envRegion") }) }; + +const athenaConnectorApp = aws.serverlessrepository.getApplication({ + applicationId: "arn:aws:serverlessrepo:us-east-1:292517598671:applications/AthenaCloudwatchConnector", +}, providerOpts); + +const spillBucket = new aws.s3.BucketV2("spill-bucket", { + bucketPrefix: "spill-bucket", + forceDestroy: true, +}, providerOpts); + +const functionName = "athena-cloudwatch-connector" +const athenaConnector = new aws.serverlessrepository.CloudFormationStack("athena-connector", { + applicationId: athenaConnectorApp.then(app => app.applicationId), + semanticVersion: athenaConnectorApp.then(app => app.semanticVersion), + capabilities: athenaConnectorApp.then(app => app.requiredCapabilities), + + parameters: { + AthenaCatalogName: functionName, + SpillBucket: spillBucket.bucket, + }, +}, providerOpts); + +const region = aws.getRegionOutput({}, providerOpts); +const identity = aws.getCallerIdentityOutput({}, providerOpts); +const partition = aws.getPartitionOutput({}, providerOpts); + +const catalog = new aws.athena.DataCatalog("cloudwatch-catalog", { + name: "cloudwatch-catalog", + description: "Example CloudWatch data catalog", + type: "LAMBDA", + parameters: { + "function": pulumi.interpolate`arn:${partition.id}:lambda:${region.name}:${identity.accountId}:function:${functionName}`, + }, +}, { ...providerOpts, dependsOn: athenaConnector }); diff --git a/examples/serverless-app-repository-application/package.json b/examples/serverless-app-repository-application/package.json new file mode 100644 index 00000000000..b694b92ddde --- /dev/null +++ b/examples/serverless-app-repository-application/package.json @@ -0,0 +1,12 @@ +{ + "name": "serverless-app-repository-application", + "main": "index.ts", + "devDependencies": { + "@types/node": "^18", + "typescript": "^5.0.0" + }, + "dependencies": { + "@pulumi/aws": "^6.0.2", + "@pulumi/pulumi": "^3.113.0" + } +} diff --git a/examples/serverless-app-repository-application/tsconfig.json b/examples/serverless-app-repository-application/tsconfig.json new file mode 100644 index 00000000000..f960d517152 --- /dev/null +++ b/examples/serverless-app-repository-application/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2020", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts" + ] +}