Skip to content

Commit 4a76eaf

Browse files
authored
Merge branch 'aws-samples:main' into lambda-durable-human-approval-sam
2 parents 8bbcb78 + 015b84c commit 4a76eaf

File tree

83 files changed

+6406
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+6406
-148
lines changed

alb-lambda-pulumi-go/go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module alb-lambda-pulumi-go
22

3-
go 1.23.0
3+
go 1.24.0
44

55
require (
66
github.com/pulumi/pulumi-aws/sdk/v5 v5.32.0
@@ -56,14 +56,14 @@ require (
5656
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
5757
github.com/xanzy/ssh-agent v0.3.3 // indirect
5858
go.uber.org/atomic v1.9.0 // indirect
59-
golang.org/x/crypto v0.36.0 // indirect
60-
golang.org/x/mod v0.17.0 // indirect
61-
golang.org/x/net v0.38.0 // indirect
62-
golang.org/x/sync v0.12.0 // indirect
63-
golang.org/x/sys v0.31.0 // indirect
64-
golang.org/x/term v0.30.0 // indirect
65-
golang.org/x/text v0.23.0 // indirect
66-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
59+
golang.org/x/crypto v0.45.0 // indirect
60+
golang.org/x/mod v0.29.0 // indirect
61+
golang.org/x/net v0.47.0 // indirect
62+
golang.org/x/sync v0.18.0 // indirect
63+
golang.org/x/sys v0.38.0 // indirect
64+
golang.org/x/term v0.37.0 // indirect
65+
golang.org/x/text v0.31.0 // indirect
66+
golang.org/x/tools v0.38.0 // indirect
6767
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
6868
google.golang.org/grpc v1.56.3 // indirect
6969
google.golang.org/protobuf v1.33.0 // indirect

alb-lambda-pulumi-go/go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
312312
golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
313313
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
314314
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
315-
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
316-
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
315+
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
316+
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
317317
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
318318
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
319319
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
@@ -325,8 +325,8 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI
325325
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
326326
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
327327
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
328-
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
329-
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
328+
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
329+
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
330330
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
331331
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
332332
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -342,17 +342,17 @@ golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/
342342
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
343343
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
344344
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
345-
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
346-
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
345+
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
346+
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
347347
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
348348
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
349349
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
350350
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
351351
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
352352
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
353353
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
354-
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
355-
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
354+
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
355+
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
356356
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
357357
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
358358
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -377,17 +377,17 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
377377
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
378378
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
379379
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
380-
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
381-
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
380+
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
381+
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
382382
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
383-
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
384-
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
383+
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
384+
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
385385
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
386386
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
387387
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
388388
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
389-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
390-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
389+
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
390+
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
391391
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
392392
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
393393
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -403,8 +403,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK
403403
golang.org/x/tools v0.0.0-20200608174601-1b747fd94509/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
404404
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
405405
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
406-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
407-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
406+
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
407+
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
408408
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
409409
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
410410
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

apigw-bedrock-nova-canvas/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Important: this application uses various AWS services and there are costs associ
2222

2323
For this pattern, you would need access only to Amazon Nova Canvas foundation model (Model ID: amazon.nova-canvas-v1:0) in us-east-1 region, since the pattern uses us-east-1 region by default.
2424

25-
You must request access to the model before you can use it. If you try to use the model before you have requested access to it, you will receive an error message.
26-
2725
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
2826
```
2927
git clone https://github.com/aws-samples/serverless-patterns
@@ -86,4 +84,4 @@ You must request access to the model before you can use it. If you try to use th
8684
----
8785
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8886
89-
SPDX-License-Identifier: MIT-0
87+
SPDX-License-Identifier: MIT-0

apigw-bedrock-nova-canvas/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "aws_iam_policy" "invoke_model_policy" {
3636
]
3737
Effect = "Allow"
3838
Resource = [
39-
"arn:aws:bedrock:${data.aws_region.current.name}::foundation-model/amazon.nova-canvas-v1:0"
39+
"arn:aws:bedrock:${data.aws_region.current.region}::foundation-model/amazon.nova-canvas-v1:0"
4040
]
4141
},
4242
]
@@ -45,23 +45,23 @@ resource "aws_iam_policy" "invoke_model_policy" {
4545

4646
# S3 bucket for storing images
4747
resource "aws_s3_bucket" "image_bucket" {
48-
bucket = "${lower(var.prefix)}-image-bucket-${random_string.suffix.result}"
48+
bucket = "${lower(var.prefix)}-image-bucket-${random_string.suffix.result}"
4949
force_destroy = true
5050
}
5151

5252
# Create CloudWatch Log Group for Lambda
5353
resource "aws_cloudwatch_log_group" "lambda_log_group" {
5454
name = "/aws/lambda/${lower(var.prefix)}-invoke-bedrock"
5555
retention_in_days = 14
56-
56+
5757
lifecycle {
5858
prevent_destroy = false
5959
}
6060
}
6161

6262
# Lambda function
6363
resource "aws_lambda_function" "invoke_bedrock_function" {
64-
filename = "index.zip" # Replace with your Lambda code zip file
64+
filename = "index.zip" # Replace with your Lambda code zip file
6565
function_name = "${lower(var.prefix)}-invoke-bedrock"
6666
role = aws_iam_role.lambda_role.arn
6767
handler = "index.handler"
@@ -146,7 +146,7 @@ resource "aws_api_gateway_integration" "lambda_integration" {
146146
# API Gateway Deployment
147147
resource "aws_api_gateway_deployment" "api_deployment" {
148148
rest_api_id = aws_api_gateway_rest_api.bedrock_api.id
149-
149+
150150
depends_on = [
151151
aws_api_gateway_integration.lambda_integration
152152
]
@@ -176,12 +176,12 @@ output "lambda_function" {
176176

177177
output "api_endpoint" {
178178
description = "The API Gateway endpoint URL "
179-
value = "${aws_api_gateway_stage.api_stage.invoke_url}/image_gen"
179+
value = "${aws_api_gateway_stage.api_stage.invoke_url}/image_gen"
180180
}
181181

182182
output "s3_image_bucket" {
183183
description = "The Output S3 bucket is "
184-
value = aws_s3_bucket.image_bucket.id
184+
value = aws_s3_bucket.image_bucket.id
185185
}
186186

187187
# Data source for current region
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lambda-layer/
2+
lambda_function.zip

apigw-lambda-bedrock-nova-terraform/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,22 @@ Key components:
8787
8888
## Testing
8989
90-
Using Curl:
90+
Using Curl:
9191
92-
```
93-
curl -X POST \
94-
-H "Content-Type: application/json" \
95-
-d '{"prompt": "What are the key benefits of using AWS services?"}' \
96-
https://YOUR-API-ENDPOINT/dev/generate_content
97-
98-
```
92+
```sh
93+
curl -X POST \
94+
-H "Content-Type: application/json" \
95+
-d '{"prompt": "What are the key benefits of using AWS services?"}' \
96+
https://YOUR-API-ENDPOINT/dev/generate_content
97+
```
9998

10099
## Viewing Test Results
101-
```
102-
{
103-
"generated-text": "<Model generated response>"
104-
}
105-
```
100+
101+
```json
102+
{
103+
"generated-text": "<Model generated response>"
104+
}
105+
```
106106

107107
## Cleanup
108108

@@ -133,4 +133,4 @@ Key components:
133133
----
134134
Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
135135

136-
SPDX-License-Identifier: MIT-0
136+
SPDX-License-Identifier: MIT-0

apigw-lambda-bedrock-nova-terraform/api_gateway.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ resource "aws_api_gateway_integration" "lambda_integration" {
1919
rest_api_id = aws_api_gateway_rest_api.generate_content_api.id
2020
resource_id = aws_api_gateway_resource.generate_content.id
2121
http_method = aws_api_gateway_method.generate_content_post.http_method
22-
22+
2323
integration_http_method = "POST"
2424
type = "AWS_PROXY"
2525
uri = aws_lambda_function.content_generation.invoke_arn
2626
}
2727

2828
resource "aws_api_gateway_deployment" "api_deployment" {
2929
rest_api_id = aws_api_gateway_rest_api.generate_content_api.id
30-
30+
3131
depends_on = [
3232
aws_api_gateway_integration.lambda_integration
3333
]

appsync-notify-subscribers-of-database-updates/1-http/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Parameters:
1717
Client:
1818
Description: Client website for authentication redirects and cors (must start with https://)
1919
Type: String
20-
Default: https://myapp.com
20+
Default: https://aws.amazon.com
2121

2222
Resources:
2323
# Creates a nested stack with the required Cognito requirements

appsync-notify-subscribers-of-database-updates/3-lambda/externalDepsLayer/nodejs/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"aws-appsync": "^4.1.10",
12+
"@aws-sdk/signature-v4": "^3.0.0",
13+
"@smithy/protocol-http": "^4.0.0",
14+
"@aws-sdk/credential-provider-node": "^3.0.0",
15+
"@aws-crypto/sha256-js": "^5.0.0",
1316
"axios": "^1.8.2",
1417
"graphql": "^16.10.0",
15-
"graphql-tag": "^2.12.6",
16-
"isomorphic-fetch": "^3.0.0"
18+
"graphql-tag": "^2.12.6"
1719
}
1820
}

appsync-notify-subscribers-of-database-updates/3-lambda/src/lambdaUsesIAM.js

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
require('isomorphic-fetch');
2-
const AUTH_TYPE = require('aws-appsync').AUTH_TYPE;
3-
const AWSAppSyncClient = require('aws-appsync').default;
1+
const { SignatureV4 } = require('@aws-sdk/signature-v4');
2+
const { HttpRequest } = require('@smithy/protocol-http');
3+
const { defaultProvider } = require('@aws-sdk/credential-provider-node');
4+
const { Sha256 } = require('@aws-crypto/sha256-js');
45
const gql = require('graphql-tag');
5-
6-
const config = {
7-
url: process.env.APPSYNC_ENDPOINT,
8-
region: process.env.AWS_REGION,
9-
auth: {
10-
type: AUTH_TYPE.AWS_IAM,
11-
credentials: {
12-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
13-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
14-
sessionToken: process.env.AWS_SESSION_TOKEN
15-
},
16-
},
17-
disableOffline: true
18-
};
6+
const graphql = require('graphql');
7+
const { print } = graphql;
198

209
const createTodo = gql`
2110
mutation MyMutation(
@@ -38,21 +27,48 @@ const createTodo = gql`
3827
}
3928
`;
4029

41-
const client = new AWSAppSyncClient(config);
30+
const signer = new SignatureV4({
31+
credentials: defaultProvider(),
32+
region: process.env.AWS_REGION,
33+
service: 'appsync',
34+
sha256: Sha256
35+
});
4236

4337
exports.handler = async function (event) {
4438
console.log("event ", event);
4539

4640
try {
47-
const result = await client.mutate({
48-
mutation: createTodo,
49-
variables: {
50-
orderId: "123",
51-
prevStatus: "PENDING",
52-
status: "IN_PROGRESS",
53-
updatedAt: "2021-10-07T20:38:18.683Z"
54-
}
41+
const url = new URL(process.env.APPSYNC_ENDPOINT);
42+
const query = print(createTodo);
43+
const variables = {
44+
orderId: "123",
45+
prevStatus: "PENDING",
46+
status: "IN_PROGRESS",
47+
updatedAt: "2021-10-07T20:38:18.683Z"
48+
};
49+
50+
const requestBody = JSON.stringify({ query, variables });
51+
52+
const request = new HttpRequest({
53+
method: 'POST',
54+
headers: {
55+
'Content-Type': 'application/json',
56+
host: url.host
57+
},
58+
hostname: url.hostname,
59+
path: url.pathname,
60+
body: requestBody
5561
});
62+
63+
const signedRequest = await signer.sign(request);
64+
65+
const response = await fetch(process.env.APPSYNC_ENDPOINT, {
66+
method: signedRequest.method,
67+
headers: signedRequest.headers,
68+
body: requestBody
69+
});
70+
71+
const result = await response.json();
5672
console.log("result ", result);
5773
} catch (error) {
5874
console.log("error ", error);

0 commit comments

Comments
 (0)