MCPcopy Create free account
hub / github.com/cdk-patterns/serverless / PollyStack

Class PollyStack

polly/java/src/main/java/com/cdkpatterns/PollyStack.java:20–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20public class PollyStack extends Stack {
21 public PollyStack(final Construct scope, final String id) {
22 this(scope, id, null);
23 }
24
25 public PollyStack(final Construct scope, final String id, final StackProps props) {
26 super(scope, id, props);
27
28 // Lambda Function that takes in text and returns a polly voice synthesis
29 Function pollyFunction = Function.Builder.create(this, "pollyHandler")
30 .runtime(Runtime.PYTHON_3_8)
31 .code(Code.fromAsset("lambda_fns"))
32 .handler("polly.handler")
33 .build();
34
35 // https://docs.aws.amazon.com/polly/latest/dg/api-permissions-reference.html
36 // https://docs.aws.amazon.com/translate/latest/dg/translate-api-permissions-ref.html
37 PolicyStatement pollyPolicy = new PolicyStatement(
38 new PolicyStatementProps
39 .Builder()
40 .effect(Effect.ALLOW)
41 .resources(List.of("*"))
42 .actions(List.of("translate:TranslateText", "polly:SynthesizeSpeech"))
43 .build());
44
45 pollyFunction.addToRolePolicy(pollyPolicy);
46
47 // defines an API Gateway Http API resource backed by our "pollyHandler" function.
48 HttpApi httpApi = HttpApi.Builder.create(this, "Polly")
49 .defaultIntegration(
50 new LambdaProxyIntegration(
51 new LambdaProxyIntegrationProps
52 .Builder()
53 .handler(pollyFunction)
54 .build()
55 ))
56 .build();
57
58 CfnOutput.Builder.create(this, "HTTP API Url")
59 .value(httpApi.getUrl())
60 .build();
61
62 }
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected