Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
...acc,
[name]: Fn.Ref(name),
}),
defaultParameterValues
);
// Also forward the API id of the top level API.
// allParamValues[ResourceConstants.RESOURCES.GraphQLAPILogicalID] = Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')
for (const stackName of stackFileNames) {
const dependsOnStacks = stackInfo.stackDependencyMap[stackName] || [];
const extraParams = stackInfo.stackParameterMap[stackName] || {};
let stackResource = new CloudFormation.Stack({
Parameters: {
...allParamValues,
...extraParams,
},
TemplateURL: Fn.Join('/', [
'https://s3.amazonaws.com',
Fn.Ref(opts.deployment.deploymentBucketParameterName),
Fn.Ref(opts.deployment.deploymentKeyParameterName),
'stacks',
stackName + '.json',
]),
}).dependsOn([...defaultDependencies, ...dependsOnStacks]);
root.Resources[stackName] = stackResource;
}
return root;
}
export function syncLambdaIAMRole({ name, region }: { name: string; region?: string }) {
return new IAM.Role({
RoleName: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
name.slice(0, 26), // max of 64. 64-10-26-28 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
Fn.Ref(ResourceConstants.PARAMETERS.Env), // 10
]),
Fn.Join('-', [
// tslint:disable-next-line: no-magic-numbers
name.slice(0, 37), // max of 64. 64-26-38 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
])
),
AssumeRolePolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Principal: {
Service: 'appsync.amazonaws.com',
},
Action: 'sts:AssumeRole',
},
],
public makeDynamoDBStreamingFunction() {
return new Lambda.Function({
Code: {
S3Bucket: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
S3Key: Fn.Join('/', [
Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
'functions',
Fn.Join('.', [ResourceConstants.RESOURCES.ElasticsearchStreamingLambdaFunctionLogicalID, 'zip']),
]),
},
FunctionName: this.joinWithEnv('-', [
Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingFunctionName),
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
]),
Handler: Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingLambdaHandlerName),
Role: Fn.GetAtt(ResourceConstants.RESOURCES.ElasticsearchStreamingLambdaIAMRoleLogicalID, 'Arn'),
Runtime: Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingLambdaRuntime),
Layers: [Fn.FindInMap('LayerResourceMapping', Fn.Ref('AWS::Region'), 'layerRegion')],
Environment: {
Variables: {
ES_ENDPOINT: Fn.Join('', ['https://', Fn.GetAtt(ResourceConstants.RESOURCES.ElasticsearchDomainLogicalID, 'DomainEndpoint')]),
ES_REGION: Fn.Select(3, Fn.Split(':', Fn.GetAtt(ResourceConstants.RESOURCES.ElasticsearchDomainLogicalID, 'DomainArn'))),
DEBUG: Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchDebugStreamingLambda),
},
private joinWithEnv(separator: string, listToJoin: any[]) {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join(separator, [...listToJoin, Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Join(separator, listToJoin)
);
}
public makeAppSyncAPI() {
return new AppSync.GraphQLApi({
Name: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName), Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName)
),
AuthenticationType: 'API_KEY',
});
}
public makeDataSourceOutput(resourceId: string): Output {
return {
Description: 'Your model DataSource name.',
Value: Fn.GetAtt(resourceId, 'Name'),
Export: {
Name: Fn.Join(':', [Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiId), 'GetAtt', resourceId, 'Name']),
},
};
}
function joinWithEnv(separator: string, listToJoin: any[]) {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join(separator, [...listToJoin, Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Join(separator, listToJoin)
);
}
export function syncLambdaIAMRole({ name, region }: { name: string; region?: string }) {
private joinWithEnv(separator: string, listToJoin: any[]) {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join(separator, [...listToJoin, Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Join(separator, listToJoin)
);
}
public makeDynamoDBStreamingFunction() {
return new Lambda.Function({
Code: {
S3Bucket: Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentBucket),
S3Key: Fn.Join('/', [
Fn.Ref(ResourceConstants.PARAMETERS.S3DeploymentRootKey),
'functions',
Fn.Join('.', [ResourceConstants.RESOURCES.ElasticsearchStreamingLambdaFunctionLogicalID, 'zip']),
]),
},
FunctionName: this.joinWithEnv('-', [
Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingFunctionName),
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
]),
Handler: Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingLambdaHandlerName),
Role: Fn.GetAtt(ResourceConstants.RESOURCES.ElasticsearchStreamingLambdaIAMRoleLogicalID, 'Arn'),
Runtime: Fn.Ref(ResourceConstants.PARAMETERS.ElasticsearchStreamingLambdaRuntime),
Layers: [Fn.FindInMap('LayerResourceMapping', Fn.Ref('AWS::Region'), 'layerRegion')],
Environment: {
Variables: {
ES_ENDPOINT: Fn.Join('', ['https://', Fn.GetAtt(ResourceConstants.RESOURCES.ElasticsearchDomainLogicalID, 'DomainEndpoint')]),