Skip to content

Commit

Permalink
Add example for deploying an application from the serverless app repo…
Browse files Browse the repository at this point in the history
…sitory (#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.
  • Loading branch information
flostadler committed Aug 23, 2024
1 parent 9e4cacb commit c02b3d3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions examples/serverless-app-repository-application/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: serverless-app-repository-application
runtime: nodejs
description: Basic example of deploying an application from the serverless app repository.
4 changes: 4 additions & 0 deletions examples/serverless-app-repository-application/README.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions examples/serverless-app-repository-application/index.ts
Original file line number Diff line number Diff line change
@@ -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: <aws.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 });
12 changes: 12 additions & 0 deletions examples/serverless-app-repository-application/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
18 changes: 18 additions & 0 deletions examples/serverless-app-repository-application/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit c02b3d3

Please sign in to comment.