-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding tests for cloudfront and lambda (#174)
This adds tests for some additional popular resources. aws-native:s3:Bucket aws-native:s3:BucketPolicy aws-native:cloudfront:KeyValueStore aws-native:cloudfront:Function aws-native:lambda:Function aws-native:iam:Role aws-native:lambda:Permission aws-native:lambda:Alias aws-native:lambda:Url aws-native:lambda:Version aws-native:cloudfront:Distribution aws-native:cloudfront:CloudFrontOriginAccessIdentity
- Loading branch information
Showing
18 changed files
with
249 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: cloudfront-lambda-urls | ||
runtime: nodejs | ||
description: cloudfront-lambda-urls CDK example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Handler, APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda'; | ||
|
||
export const handler: Handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => { | ||
return { | ||
statusCode: 200, | ||
body: 'Hello world!', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import { Code, FunctionUrlAuthType, Runtime } from 'aws-cdk-lib/aws-lambda'; | ||
import { | ||
Distribution, | ||
experimental, | ||
Function, | ||
FunctionCode, | ||
FunctionEventType, | ||
FunctionRuntime, | ||
KeyValueStore, | ||
LambdaEdgeEventType, | ||
} from 'aws-cdk-lib/aws-cloudfront'; | ||
import { FunctionUrlOrigin, S3Origin } from 'aws-cdk-lib/aws-cloudfront-origins'; | ||
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; | ||
import { Bucket } from 'aws-cdk-lib/aws-s3'; | ||
|
||
class CloudFrontAppStack extends pulumicdk.Stack { | ||
public cloudFrontUrl: pulumi.Output<string>; | ||
constructor(id: string) { | ||
super(id); | ||
|
||
const handler = new NodejsFunction(this, 'handler', { | ||
runtime: Runtime.NODEJS_LATEST, | ||
}); | ||
|
||
const cfFunction = new Function(this, 'CfFunction', { | ||
code: FunctionCode.fromInline('export function handler(event) { return event.request }'), | ||
runtime: FunctionRuntime.JS_2_0, | ||
}); | ||
|
||
const alias = handler.addAlias('live'); | ||
const url = alias.addFunctionUrl({ | ||
authType: FunctionUrlAuthType.NONE, | ||
}); | ||
|
||
const bucket = new Bucket(this, 'Bucket'); | ||
|
||
const distro = new Distribution(this, 'distro', { | ||
defaultBehavior: { | ||
origin: new FunctionUrlOrigin(url), | ||
functionAssociations: [ | ||
{ | ||
function: cfFunction, | ||
eventType: FunctionEventType.VIEWER_REQUEST, | ||
}, | ||
], | ||
}, | ||
}); | ||
distro.addBehavior('/images/*', new S3Origin(bucket)); | ||
|
||
new KeyValueStore(this, 'KVStore'); | ||
|
||
this.cloudFrontUrl = this.asOutput(distro.distributionDomainName); | ||
|
||
this.synth(); | ||
} | ||
} | ||
|
||
const stack = new CloudFrontAppStack('cloudfront-app'); | ||
export const url = pulumi.interpolate`https://${stack.cloudFrontUrl}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cloudfront-lambda-urls", | ||
"devDependencies": { | ||
"@types/node": "^10.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/aws-native": "^1.0.0", | ||
"@pulumi/cdk": "^0.5.0", | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@types/aws-lambda": "^8.10.145", | ||
"aws-cdk-lib": "2.149.0", | ||
"aws-lambda": "^1.0.7", | ||
"constructs": "10.3.0", | ||
"esbuild": "^0.24.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.