-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.64.0 (to main)
- Loading branch information
Showing
55 changed files
with
7,161 additions
and
282 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
46 changes: 46 additions & 0 deletions
46
integration/resources/expected/combination/connector_appsync_to_lambda.json
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,46 @@ | ||
[ | ||
{ | ||
"LogicalResourceId": "HelloLambda", | ||
"ResourceType": "AWS::Lambda::Function" | ||
}, | ||
{ | ||
"LogicalResourceId": "HelloLambdaRole", | ||
"ResourceType": "AWS::IAM::Role" | ||
}, | ||
{ | ||
"LogicalResourceId": "AppSyncApi", | ||
"ResourceType": "AWS::AppSync::GraphQLApi" | ||
}, | ||
{ | ||
"LogicalResourceId": "ApiKey", | ||
"ResourceType": "AWS::AppSync::ApiKey" | ||
}, | ||
{ | ||
"LogicalResourceId": "ApiSchema", | ||
"ResourceType": "AWS::AppSync::GraphQLSchema" | ||
}, | ||
{ | ||
"LogicalResourceId": "AppSyncLambdaDataSource", | ||
"ResourceType": "AWS::AppSync::DataSource" | ||
}, | ||
{ | ||
"LogicalResourceId": "TriggerFunction", | ||
"ResourceType": "AWS::Lambda::Function" | ||
}, | ||
{ | ||
"LogicalResourceId": "TriggerFunctionRole", | ||
"ResourceType": "AWS::IAM::Role" | ||
}, | ||
{ | ||
"LogicalResourceId": "AppSyncApiLambdaInvocationRole", | ||
"ResourceType": "AWS::IAM::Role" | ||
}, | ||
{ | ||
"LogicalResourceId": "DataSourceToLambdaConnectorPolicy", | ||
"ResourceType": "AWS::IAM::ManagedPolicy" | ||
}, | ||
{ | ||
"LogicalResourceId": "AppSyncSayHelloResolver", | ||
"ResourceType": "AWS::AppSync::Resolver" | ||
} | ||
] |
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
162 changes: 162 additions & 0 deletions
162
integration/resources/templates/combination/connector_appsync_to_lambda.yaml
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,162 @@ | ||
Resources: | ||
AppSyncApiLambdaInvocationRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: appsync.amazonaws.com | ||
Action: | ||
- sts:AssumeRole | ||
|
||
HelloLambda: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
InlineCode: | | ||
exports.handler = async (_) => { | ||
return "Hello World" | ||
} | ||
Handler: index.handler | ||
Runtime: nodejs14.x | ||
|
||
AppSyncApi: | ||
Type: AWS::AppSync::GraphQLApi | ||
Properties: | ||
AuthenticationType: API_KEY | ||
Name: AppSyncApi | ||
|
||
ApiSchema: | ||
Type: AWS::AppSync::GraphQLSchema | ||
Properties: | ||
ApiId: !GetAtt AppSyncApi.ApiId | ||
Definition: | | ||
type Query { | ||
sayHello: String! | ||
} | ||
schema { | ||
query: Query | ||
} | ||
AppSyncLambdaDataSource: | ||
Type: AWS::AppSync::DataSource | ||
Properties: | ||
ApiId: !GetAtt AppSyncApi.ApiId | ||
Name: AppSyncLambdaDataSource | ||
Type: AWS_LAMBDA | ||
ServiceRoleArn: !GetAtt AppSyncApiLambdaInvocationRole.Arn | ||
LambdaConfig: | ||
LambdaFunctionArn: !GetAtt HelloLambda.Arn | ||
|
||
AppSyncSayHelloResolver: | ||
DependsOn: ApiSchema | ||
Type: AWS::AppSync::Resolver | ||
Properties: | ||
ApiId: !GetAtt AppSyncApi.ApiId | ||
TypeName: Query | ||
FieldName: sayHello | ||
DataSourceName: !GetAtt AppSyncLambdaDataSource.Name | ||
RequestMappingTemplate: | | ||
{ | ||
"version" : "2017-02-28", | ||
"operation": "Invoke", | ||
"payload": $util.toJson($context.args) | ||
} | ||
ResponseMappingTemplate: | | ||
$util.toJson($context.result) | ||
DataSourceToLambdaConnector: | ||
Type: AWS::Serverless::Connector | ||
Properties: | ||
Source: | ||
Id: AppSyncLambdaDataSource | ||
Destination: | ||
Id: HelloLambda | ||
Permissions: | ||
- Write | ||
|
||
ApiKey: | ||
Type: AWS::AppSync::ApiKey | ||
Properties: | ||
ApiId: !GetAtt AppSyncApi.ApiId | ||
|
||
TriggerFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Environment: | ||
Variables: | ||
API_KEY: !GetAtt ApiKey.ApiKey | ||
GRAPHQL_URL: !GetAtt AppSyncApi.GraphQLUrl | ||
Runtime: nodejs14.x | ||
Handler: index.handler | ||
InlineCode: | | ||
const https = require("https"); | ||
exports.handler = async (_) => { | ||
const queries = { | ||
sayHello: /* GraphQL */ ` | ||
query { | ||
sayHello | ||
} | ||
`, | ||
}; | ||
const fetch = async (url, options) => | ||
new Promise((resolve, reject) => { | ||
const req = https.request(url, options, (res) => { | ||
const body = []; | ||
res.on("data", (chunk) => body.push(chunk)); | ||
res.on("end", () => { | ||
const resString = Buffer.concat(body).toString(); | ||
resolve(resString); | ||
}); | ||
}); | ||
req.on("error", (err) => { | ||
reject(err); | ||
}); | ||
req.on("timeout", () => { | ||
req.destroy(); | ||
reject(new Error("Request time out")); | ||
}); | ||
req.write(options.body); | ||
req.end(); | ||
}); | ||
const makeRequest = async (queryName) => { | ||
const options = { | ||
method: "POST", | ||
headers: { | ||
"x-api-key": process.env.API_KEY, | ||
}, | ||
body: JSON.stringify({ query: queries[queryName] }), | ||
timeout: 10000, // ms | ||
}; | ||
const response = await fetch(process.env.GRAPHQL_URL, options); | ||
const body = JSON.parse(response); | ||
const data = body.data?.[queryName]; | ||
if (body.errors !== undefined) { | ||
throw JSON.stringify(body.errors); | ||
} | ||
if (data !== "Hello World") { | ||
throw new Error(`${queryName} error: '${data}' must be 'Hello World'`); | ||
} | ||
return body.data; | ||
}; | ||
return await makeRequest("sayHello"); | ||
}; | ||
Metadata: | ||
SamTransformTest: true |
Oops, something went wrong.